File: getBinaryContents.js

package info (click to toggle)
greasemonkey 2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,820 kB
  • sloc: xml: 171; makefile: 10
file content (17 lines) | stat: -rw-r--r-- 602 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Components.utils.import('resource://greasemonkey/util.js');

const EXPORTED_SYMBOLS = ['getBinaryContents'];

const ioService = Components.classes["@mozilla.org/network/io-service;1"]
    .getService(Components.interfaces.nsIIOService);

function getBinaryContents(file) {
  var channel = ioService.newChannelFromURI(GM_util.getUriFromFile(file));
  var input = channel.open();

  var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
      .createInstance(Components.interfaces.nsIBinaryInputStream);
  bstream.setInputStream(input);

  return bstream.readBytes(bstream.available());
}