B2G/gecko/toolkit/mozapps/update/test/shared.js
/**
 * Reads the binary contents of a file and returns it as a string.
 *
 * @param  aFile
 *         The file to read from.
 * @return The contents of the file as a string.
 */
Reads the binary contents of a file and returns it as a string.
@param  aFile
The file to read from.
@return The contents of the file as a string.
Reads the binary contents of a file and returns it as a string . @param aFile The file to read from . @return The contents of the file as a string .
function readFileBytes(aFile) {
  var fis = AUS_Cc["@mozilla.org/network/file-input-stream;1"].
            createInstance(AUS_Ci.nsIFileInputStream);
  fis.init(aFile, -1, -1, false);
  var bis = AUS_Cc["@mozilla.org/binaryinputstream;1"].
            createInstance(AUS_Ci.nsIBinaryInputStream);
  bis.setInputStream(fis);
  var data = [];
  var count = fis.available();
  while (count > 0) {
    var bytes = bis.readByteArray(Math.min(65535, count));
    data.push(String.fromCharCode.apply(null, bytes));
    count -= bytes.length;
    if (bytes.length == 0)
      throw "Nothing read from input stream!";
  }
  data.join('');
  fis.close();
  return data.toString();
}
function readFileBytes ( aFile ) { var fis = AUS_Cc [ "@mozilla.org/network/file-input-stream;1" ] . createInstance ( AUS_Ci . nsIFileInputStream ) ; fis . init ( aFile , - 1 , - 1 , false ) ; var bis = AUS_Cc [ "@mozilla.org/binaryinputstream;1" ] . createInstance ( AUS_Ci . nsIBinaryInputStream ) ; bis . setInputStream ( fis ) ; var data = [ ] ; var count = fis . available ( ) ; while ( count > 0 ) { var bytes = bis . readByteArray ( Math . min ( 65535 , count ) ) ; data . push ( String . fromCharCode . apply ( null , bytes ) ) ; count -= bytes . length ; if ( bytes . length == 0 ) throw "Nothing read from input stream!" ; } data . join ( '' ) ; fis . close ( ) ; return data . toString ( ) ; }
Reads the binary contents of a file and returns it as a string.
Reads the binary contents of a file and returns it as a string .