Thanks Boris.

Referring to two more samples reading out a js string out of an input
stream:
<http://developer.mozilla.org/en/docs/Reading_textual_data#Gecko_1.8_and_newer>
<http://developer.mozilla.org/en/docs/Code_snippets:File_I/O#Simple>

Are those correct?

The latter uses a scriptable input stream and the scriptable input
stream implementation reads out available() bytes at most:
<http://mxr.mozilla.org/mozilla1.8/source/xpcom/io/nsScriptableInputStream.cpp#65>

So IMO one can run into the same problem, closing reading too early.

But after all, what's the correct way of reading out an entire stream
into a js string then?

thanks for your help, regards,
Daniel

Boris Zbarsky wrote:
> Daniel Boelzle wrote:
>> If nsIInputStream::available() denotes the *currently* available number
>> of bytes, then why do some samples only use available() once to read out
>> the entire data?
> 
> Because those samples are buggy?  Most likely because the author of the code 
> didn't actually test it very well against arbitrary streams.
> 
>> <http://developer.mozilla.org/en/docs/Code_snippets:File_I/O#Binary_File>
> 
> In the particular case of a file input stream, I believe all the data is 
> available immediately.  But that code, as written, is certainly very fragile.
> 
> -Boris
_______________________________________________
dev-tech-network mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-network

Reply via email to