Skip to content

Commit fa55736

Browse files
committed
Convert lz4-compress.js to mjs. NFC
1 parent 2ba2078 commit fa55736

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

third_party/mini-lz4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,4 @@ return exports;
343343

344344
})();
345345

346+
module.exports = MiniLZ4;

tools/file_packager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,8 @@ def generate_js(data_target, data_files, metadata):
745745
# LZ4FS usage
746746
temp = data_target + '.orig'
747747
shutil.move(data_target, temp)
748-
meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.js'),
749-
[utils.path_from_root('third_party/mini-lz4.js'),
750-
temp, data_target], stdout=PIPE)
748+
meta = shared.run_js_tool(utils.path_from_root('tools/lz4-compress.mjs'),
749+
[temp, data_target], stdout=PIPE)
751750
os.unlink(temp)
752751
use_data = '''var compressedData = %s;
753752
compressedData['data'] = byteArray;

tools/lz4-compress.js renamed to tools/lz4-compress.mjs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
// University of Illinois/NCSA Open Source License. Both these licenses can be
55
// found in the LICENSE file.
66

7-
'use strict';
7+
import * as fs from 'fs';
8+
import * as path from 'path';
89

9-
const fs = require('fs');
10-
const path = require('path');
10+
globalThis.assert = (x, message) => {
11+
if (!x) throw new Error(message);
12+
};
1113

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

1516
function print(x) {
1617
process.stdout.write(x + '\n');
@@ -39,19 +40,13 @@ function load(f) {
3940
globalEval(read(f));
4041
}
4142

42-
global.assert = (x, message) => {
43-
if (!x) throw new Error(message);
44-
};
45-
4643
// Redirect console.log message from MiniLZ4 to stderr since stdout is
4744
// where we return the decompressed data.
4845
console.log = printErr;
4946

50-
const lz4 = arguments_[0];
51-
const input = arguments_[1];
52-
const output = arguments_[2];
53-
54-
load(lz4);
47+
const arguments_ = process.argv.slice(2);
48+
const input = arguments_[0];
49+
const output = arguments_[1];
5550

5651
const data = new Uint8Array(readBinary(input)).buffer;
5752
const start = Date.now();

0 commit comments

Comments
 (0)