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
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