Browser Console Snippet to decompress mozlz4 and jsonlz4 files
/* Decompression Script for the Browser Console | |
NOTE: BEFORE RUNNING THIS SCRIPT, CHECK THIS SETTING: | |
Type or paste about:config into the address bar and press Enter | |
Click the button promising to be careful | |
In the search box type devt and pause while Firefox filters the list | |
If devtools.chrome.enabled is false, double-click it to toggle to true | |
Paste this entire script into the command line at the bottom of the Browser Console (Windows: Ctrl+Shift+j) | |
Then press Enter to run the script. A file picker should promptly open. | |
See: http://forums.mozillazine.org/viewtopic.php?p=14111285#p14111285 | |
*/ | |
var {utils:Cu} = Components; | |
// Set up file chooser | |
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); | |
var fu = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils | |
fp.init(window, "Open File", Components.interfaces.nsIFilePicker.modeOpen); | |
fp.appendFilter("LZ4 Compressed Files", "*.mozlz4;*.jsonlz4*"); | |
fp.displayDirectory = fu.File(OS.Constants.Path.profileDir); | |
// Call file chooser | |
fp.open((aResult) => { | |
if (aResult == Components.interfaces.nsIFilePicker.returnOK) { | |
if (fp.file.exists() && fp.file.isFile() && fp.file.isReadable()) { | |
var oldfile = fp.file.path; | |
// Construct output file name | |
var newfile = oldfile + "_converted.json"; | |
try { | |
Cu.import("resource://gre/modules/osfile.jsm"); | |
let promise = OS.File.read(oldfile,{compression:"lz4"}); | |
promise = promise.then(jsonString => { | |
OS.File.writeAtomic(newfile, jsonString); | |
}); | |
promise = promise.then(retval => { | |
console.log('Saved as: "' + newfile + '"'); | |
}); | |
} | |
catch (err) { | |
console.log(err); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
I created a pair of webapps that are simpler to use: