我试图使用OS.File将Chrome路径复制到桌面,但它一直在抛出错误。这可能吗?
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())
}
);
答案 0 :(得分:3)
由于chrome://branding/content/icon16.png
不是文件,我猜你不能。
但可以在NetUtli
和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);
}
)
})