NetUtil.readInputStreamToString() should make aCount optional

Assigned to



7 years ago
6 months ago


(Reporter: philikon, Assigned: philikon)


Firefox Tracking Flags

(Not tracked)


(Whiteboard: [necko-would-take])


(1 attachment)

If aCount isn't passed in we can just default it to aInputStream.available().
Alright, this has annoyed me long enough. I whipped up a patch this morning. Will attach shortly, after having built + run tests...
Assignee: nobody → philipp
Created attachment 550455 [details] [diff] [review]
Attachment #550455 - Flags: superreview?(cbiesinger)
Attachment #550455 - Flags: review?(sdwilsh)
Comment on attachment 550455 [details] [diff] [review]

Wouldn't it make more sense to read until EOF?
09:59 < philikon> biesi: so how would reading till EOF work? continue to read until stream.available() throws?
10:00 < philikon> biesi: and call the callback multiple times in the process?
10:00 < biesi> philikon, continue calling read() until it returns null bytes
10:00 < biesi> hm?
10:00 < biesi> no, just call it once with everything
10:00 < philikon> hmmmm
10:00 < biesi> although, you're using binaryinputstream, it seems
10:00 < biesi> so that doesn't quite work that way
10:02 < biesi> scriptableinputstream, right
10:02 < biesi> so you can just do:
10:02 < biesi> for (;;) { newData =; if (newData.length == 0) break; retval += newData; }
10:04 < philikon> you mean readBytes, right?
10:04 < biesi> er, yes
10:04 < philikon> and why not read what's available?
10:04 < philikon> js string concat: probably not super awesome
10:05 < philikon> best to avoid it when we can
10:07 < biesi> you mean keep reading what's available()?
10:07 < philikon> yes
10:08 < biesi> that'd have weird semantics with nonblocking streams
10:08 < philikon> i guess available() could return 0
10:08 < biesi> it can return 0 at EOF or when nonblocking
10:09 < biesi> (when nonblocking and no data is available right now)
10:09 < biesi> hrm
10:09 < biesi> but maybe that's actually the better semantics
10:09 < biesi> if nonblocking you'll want partial data over an exception + lost data
10:09 < philikon> yes
10:11 < biesi> sounds good then, loop and read what's available() until that returns 0
10:11 < biesi> though it's somewhat unfortunate that you have no way of telling whether you're at EOF
10:12 < biesi> (vs nonblocking+no data right now)
Attachment #550455 - Flags: superreview?(cbiesinger) → superreview-
Comment on attachment 550455 [details] [diff] [review]

Clearing request until the right approach is worked out.
Attachment #550455 - Flags: review?(sdwilsh)
Whiteboard: [necko-would-take]
You need to log in before you can comment on or make changes to this bug.