Created
February 15, 2020 02:04
-
-
Save intelguasoft/aa133c98be77064bcd5601f7b3ffce98 to your computer and use it in GitHub Desktop.
How to save a file from js (from tiddlywiki code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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