Skip to content

Commit

Permalink
Convert lz4-compress.js to mjs. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Mar 11, 2024
1 parent 2ba2078 commit fa55736
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions third_party/mini-lz4.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,4 @@ return exports;

})();

module.exports = MiniLZ4;
5 changes: 2 additions & 3 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,8 @@ def generate_js(data_target, data_files, metadata):
# LZ4FS usage
temp = data_target + '.orig'
shutil.move(data_target, temp)
meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.js'),
[utils.path_from_root('third_party/mini-lz4.js'),
temp, data_target], stdout=PIPE)
meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.mjs'),
[temp, data_target], stdout=PIPE)
os.unlink(temp)
use_data = '''var compressedData = %s;
compressedData['data'] = byteArray;
Expand Down
23 changes: 9 additions & 14 deletions tools/lz4-compress.js → tools/lz4-compress.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

'use strict';
import * as fs from 'fs';
import * as path from 'path';

const fs = require('fs');
const path = require('path');
globalThis.assert = (x, message) => {
if (!x) throw new Error(message);
};

const arguments_ = process.argv.slice(2);
const debug = false;
const MiniLZ4 = await import('../third_party/mini-lz4.js');

function print(x) {
process.stdout.write(x + '\n');
Expand Down Expand Up @@ -39,19 +40,13 @@ function load(f) {
globalEval(read(f));
}

global.assert = (x, message) => {
if (!x) throw new Error(message);
};

// Redirect console.log message from MiniLZ4 to stderr since stdout is
// where we return the decompressed data.
console.log = printErr;

const lz4 = arguments_[0];
const input = arguments_[1];
const output = arguments_[2];

load(lz4);
const arguments_ = process.argv.slice(2);
const input = arguments_[0];
const output = arguments_[1];

const data = new Uint8Array(readBinary(input)).buffer;
const start = Date.now();
Expand Down

0 comments on commit fa55736

Please sign in to comment.