Skip to content

Instantly share code, notes, and snippets.

@jscher2000
Last active December 18, 2024 16:10

Revisions

  1. jscher2000 revised this gist Dec 18, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion decompress-mozlz4-snippet.js
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ fp.open((aResult) => {
    // Construct output file name
    var newfile = oldfile + "_converted.json";
    try {
    Cu.import("resource://gre/modules/osfile.jsm");
    //Cu.import("resource://gre/modules/osfile.jsm");
    //let promise = OS.File.read(oldfile,{compression:"lz4"});
    let promise = IOUtils.readUTF8(oldfile, { decompress: true }); // Fx104
    promise = promise.then(jsonString => {
  2. jscher2000 revised this gist Mar 18, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion decompress-mozlz4-snippet.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,11 @@ 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);
    try { // Fx125+
    fp.init(window.browsingContext, 'Open File', Components.interfaces.nsIFilePicker.modeOpen);
    } catch(e) { // Fx124 and earlier
    fp.init(window, 'Open File', Components.interfaces.nsIFilePicker.modeOpen);
    }
    fp.appendFilter("LZ4 Compressed Files", "*.mozlz4;*.jsonlz4*");
    //fp.displayDirectory = fu.File(OS.Constants.Path.profileDir);
    fp.displayDirectory = fu.File(PathUtils.profileDir); // Fx104
  3. jscher2000 revised this gist Aug 30, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions decompress-mozlz4-snippet.js
    Original file line number Diff line number Diff line change
    @@ -29,10 +29,10 @@ fp.open((aResult) => {
    try {
    Cu.import("resource://gre/modules/osfile.jsm");
    //let promise = OS.File.read(oldfile,{compression:"lz4"});
    let promise = IOUtils.readUTF8(oldfile, { decompress: true }); // Fx104
    let promise = IOUtils.readUTF8(oldfile, { decompress: true }); // Fx104
    promise = promise.then(jsonString => {
    //OS.File.writeAtomic(newfile, jsonString);
    IOUtils.writeUTF8(newfile, jsonString); // Fx104
    IOUtils.writeUTF8(newfile, jsonString); // Fx104
    });
    promise = promise.then(retval => {
    console.log('Saved as: "' + newfile + '"');
  4. jscher2000 revised this gist Aug 30, 2022. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions decompress-mozlz4-snippet.js
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,8 @@ var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Componen
    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);
    //fp.displayDirectory = fu.File(OS.Constants.Path.profileDir);
    fp.displayDirectory = fu.File(PathUtils.profileDir); // Fx104
    // Call file chooser
    fp.open((aResult) => {
    if (aResult == Components.interfaces.nsIFilePicker.returnOK) {
    @@ -27,9 +28,11 @@ fp.open((aResult) => {
    var newfile = oldfile + "_converted.json";
    try {
    Cu.import("resource://gre/modules/osfile.jsm");
    let promise = OS.File.read(oldfile,{compression:"lz4"});
    //let promise = OS.File.read(oldfile,{compression:"lz4"});
    let promise = IOUtils.readUTF8(oldfile, { decompress: true }); // Fx104
    promise = promise.then(jsonString => {
    OS.File.writeAtomic(newfile, jsonString);
    //OS.File.writeAtomic(newfile, jsonString);
    IOUtils.writeUTF8(newfile, jsonString); // Fx104
    });
    promise = promise.then(retval => {
    console.log('Saved as: "' + newfile + '"');
  5. jscher2000 renamed this gist Sep 14, 2021. 1 changed file with 0 additions and 0 deletions.
  6. jscher2000 revised this gist Mar 27, 2019. 1 changed file with 25 additions and 29 deletions.
    54 changes: 25 additions & 29 deletions decompress-mozlz4-snippet.txt
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,17 @@
    /*
    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
    /* 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;
    function decompressBookmarksFile(oFilePath,nFilePath){
    Cu.import("resource://gre/modules/Task.jsm");
    Cu.import("resource://gre/modules/osfile.jsm");
    return Task.spawn(function* () {
    var jsonString = yield OS.File.read(oFilePath,{compression:"lz4"});
    yield OS.File.writeAtomic(nFilePath, jsonString);})
    }
    // 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
    @@ -27,21 +21,23 @@ 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 {
    decompressBookmarksFile(oldfile, newfile);
    console.log("Saved as: \"" + newfile + "\"");
    if(confirm("Open JSON file in a Firefox tab?")){
    var uri="file:///"+newfile.replace(/\\/g, "/");
    window.open(uri, "_blank");
    }
    }
    catch (err) {
    console.log(err);
    }
    }
    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);
    }
    }
    }
    });
  7. jscher2000 created this gist Sep 17, 2017.
    47 changes: 47 additions & 0 deletions decompress-mozlz4-snippet.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    /*
    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;
    function decompressBookmarksFile(oFilePath,nFilePath){
    Cu.import("resource://gre/modules/Task.jsm");
    Cu.import("resource://gre/modules/osfile.jsm");
    return Task.spawn(function* () {
    var jsonString = yield OS.File.read(oFilePath,{compression:"lz4"});
    yield OS.File.writeAtomic(nFilePath, jsonString);})
    }
    // 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 {
    decompressBookmarksFile(oldfile, newfile);
    console.log("Saved as: \"" + newfile + "\"");
    if(confirm("Open JSON file in a Firefox tab?")){
    var uri="file:///"+newfile.replace(/\\/g, "/");
    window.open(uri, "_blank");
    }
    }
    catch (err) {
    console.log(err);
    }
    }
    }
    });