It looks like you would like to write not the data URI, but the binary data that it โcontainsโ, so I will answer that.
, URI ( , data:application/octet-stream;base64, ;)
var imageDataURI = "data:application/octet-stream;base64,aGVsbG93b3JsZA==";
1 - OS.File
OS.File , . , NetUtil , stat , ( , , , ).
( ), OS.File.writeAtomic .
Components.utils.import("resource://gre/modules/osfile.jsm");
var file = OS.Path.join(OS.Constants.Path.desktopDir, "test.png");
var str = imageDataURI.replace(/^.*?;base64,/, "");
str = atob(str);
var data = new Uint8Array(str.length);
for (var i = 0, e = str.length; i < e; ++i) {
data[i] = str.charCodeAt(i);
}
var promised = OS.File.writeAtomic(file, data);
promised.then(
function() {
},
function(ex) {
}
);
2 - NetUtil
NetUtil , async, .
, NetUtil.asyncFetch URL-, , .asyncCopy.
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("Desk", ["test.png"]);
NetUtil.asyncFetch(imageDataURI, function(inputstream, status) {
if (!inputstream || !Components.isSuccessCode(status)) {
return;
}
var ostream = FileUtils.openSafeFileOutputStream(file);
NetUtil.asyncCopy(inputstream , ostream, function(status) {
if (!Components.isSuccessCode(status)) {
return;
}
});
});