Skip to content

Instantly share code, notes, and snippets.

@intelguasoft
Created February 15, 2020 02:04
Show Gist options
  • Save intelguasoft/aa133c98be77064bcd5601f7b3ffce98 to your computer and use it in GitHub Desktop.
Save intelguasoft/aa133c98be77064bcd5601f7b3ffce98 to your computer and use it in GitHub Desktop.
How to save a file from js (from tiddlywiki code)
function mozillaSaveFile(filePath,content)
{
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
file.create(0,0664);
var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
out.init(file,0x20|0x02,00004,null);
out.write(content,content.length);
out.flush();
out.close();
return true;
} catch(ex) {
return false;
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment