B2G/gecko/netwerk/test/unit/head_channels.js
/**
 * Read count bytes from stream and return as a String object
 */
Read count bytes from stream and return as a String object
Read count bytes from stream and return as a String object
function read_stream(stream, count) {
  var wrapper =
      Components.classes["@mozilla.org/binaryinputstream;1"]
                .createInstance(Components.interfaces.nsIBinaryInputStream);
  wrapper.setInputStream(stream);
  var data = [];
  while (count > 0) {
    var bytes = wrapper.readByteArray(Math.min(65535, count));
    data.push(String.fromCharCode.apply(null, bytes));
    count -= bytes.length;
    if (bytes.length == 0)
      do_throw("Nothing read from input stream!");
  }
  return data.join('');
}
function read_stream ( stream , count ) { var wrapper = Components . classes [ "@mozilla.org/binaryinputstream;1" ] . createInstance ( Components . interfaces . nsIBinaryInputStream ) ; wrapper . setInputStream ( stream ) ; var data = [ ] ; while ( count > 0 ) { var bytes = wrapper . readByteArray ( Math . min ( 65535 , count ) ) ; data . push ( String . fromCharCode . apply ( null , bytes ) ) ; count -= bytes . length ; if ( bytes . length == 0 ) do_throw ( "Nothing read from input stream!" ) ; } return data . join ( '' ) ; }
Read count bytes from stream and return as a String object
Read count bytes from stream and return as a String object
/* assume stream has non-ASCII data */ /* JS methods can be called with a maximum of 65535 arguments, and input
     streams don't have to return all the data they make .available() when
     asked to .read() that number of bytes. */