Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reading binary data from file

23 views
Skip to first unread message

Marek 'MMx' Ludha

unread,
Oct 2, 2006, 7:49:12 AM10/2/06
to
Hi.

I need to read binary data from file. So far I have tried

var inStream =
Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
inStream.init(cFile, 0x01, 0600, 0);
var sStream =
Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
sStream.init(inStream);
var data = "";
data = sStream.read(sStream.available());

sStream.available() tells the correct number of bytes available, but
sStream.read() stops reading on the first zero byte. I have also tried
nsIBinaryInputStream:

var sStream =
Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
sStream.setInputStream(inStream);
var byteArray = [];
sStream.readByteArray(sStream.available(), byteArray);

sStream.available() still works as expected, but
sStream.readByteArray() leaves byteArray unchanged.
Can anyone point me the right direction please? Thanks in advance for
any answer.

--
Marek 'MMx' Ludha

Christian Biesinger

unread,
Oct 3, 2006, 5:58:57 PM10/3/06
to dev-tec...@lists.mozilla.org
Marek 'MMx' Ludha wrote:
> sStream.available() tells the correct number of bytes available, but
> sStream.read() stops reading on the first zero byte.

Yeah, you can't use nsIScriptableInputStream for binary data, unfortunately.

> var byteArray = [];
> sStream.readByteArray(sStream.available(), byteArray);

This needs to be:
var byteArray = sStream.readByteArray(sStream.available());
then it should work.

-christian

0 new messages