Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/lz4-compress.mjs
4128 views
1
#!/usr/bin/env node
2
// Copyright 2015 The Emscripten Authors. All rights reserved.
3
// Emscripten is available under two separate licenses, the MIT license and the
4
// University of Illinois/NCSA Open Source License. Both these licenses can be
5
// found in the LICENSE file.
6
7
import * as fs from 'node:fs';
8
import * as path from 'node:path';
9
10
function print(x) {
11
process.stdout.write(x + '\n');
12
}
13
14
function printErr(x) {
15
process.stderr.write(x + '\n');
16
}
17
18
globalThis.assert = (x, message) => {
19
if (!x) throw new Error(message);
20
};
21
22
// Redirect console.log message from MiniLZ4 to stderr since stdout is
23
// where we return the decompressed data.
24
console.log = printErr;
25
26
const MiniLZ4 = await import('../third_party/mini-lz4.js');
27
28
function readBinary(filename) {
29
filename = path.normalize(filename);
30
return fs.readFileSync(filename);
31
}
32
33
const arguments_ = process.argv.slice(2);
34
const input = arguments_[0];
35
const output = arguments_[1];
36
37
const data = new Uint8Array(readBinary(input)).buffer;
38
const start = Date.now();
39
const compressedData = MiniLZ4.compressPackage(data);
40
fs.writeFileSync(output, Buffer.from(compressedData['data']));
41
compressedData['data'] = null;
42
printErr('compressed in ' + (Date.now() - start) + ' ms');
43
print(JSON.stringify(compressedData));
44
45