Skip to content

Instantly share code, notes, and snippets.

@padenot
Created June 1, 2011 09:56
Show Gist options
  • Save padenot/1002059 to your computer and use it in GitHub Desktop.
Save padenot/1002059 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