Q:

OS.File copy chrome file to desktop

I'm trying to use OS.File to copy a chrome path to desktop but it keeps throwing errors. Is this possible?
var promise = OS.File.copy('chrome://branding/content/icon16.png', OS.Path.join(OS.Constants.Path.desktopDir, 'copied.png'));
promise.then(
  function(aVal) {
    console.log('suc')
  },
  function(aReason) {
    console.error('FAIL, aReason:', aReason)
    console.error('FAIL, aReason:', aReason.toString())
  }
);

A:

Since chrome://branding/content/icon16.png is not a file, I guess you can't.
But it is possible to split the job between NetUtli and OS.File
NetUtil.asyncFetch("chrome://branding/content/icon16.png", function(inputstream, code){
  var bis = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
  bis.setInputStream(inputstream);
  var data = new Uint8Array(bis.available());
  bis.readArrayBuffer(data.length, data.buffer);

  OS.File.open(OS.Path.join(OS.Constants.Path.desktopDir, 'copied.png'), {write: true, append: false, create: true}).then(
    function success(file){
      file.write(data);
      file.close();
    },
    function fail(reason){
      console.log(reason);
    }
  )
})

