4
4
// University of Illinois/NCSA Open Source License. Both these licenses can be
5
5
// found in the LICENSE file.
6
6
7
- 'use strict' ;
8
-
9
- const fs = require ( 'fs' ) ;
10
- const path = require ( 'path' ) ;
11
-
12
- const arguments_ = process . argv . slice ( 2 ) ;
13
- const debug = false ;
7
+ import * as fs from 'fs' ;
8
+ import * as path from 'path' ;
14
9
15
10
function print ( x ) {
16
11
process . stdout . write ( x + '\n' ) ;
@@ -20,38 +15,24 @@ function printErr(x) {
20
15
process . stderr . write ( x + '\n' ) ;
21
16
}
22
17
23
- function read ( filename , binary ) {
24
- filename = path . normalize ( filename ) ;
25
- let ret = fs . readFileSync ( filename ) ;
26
- if ( ret && ! binary ) ret = ret . toString ( ) ;
27
- return ret ;
28
- }
29
-
30
- function readBinary ( filename ) {
31
- return read ( filename , true ) ;
32
- }
33
-
34
- function globalEval ( x ) {
35
- eval . call ( null , x ) ;
36
- }
37
-
38
- function load ( f ) {
39
- globalEval ( read ( f ) ) ;
40
- }
41
-
42
- global . assert = ( x , message ) => {
18
+ globalThis . assert = ( x , message ) => {
43
19
if ( ! x ) throw new Error ( message ) ;
44
20
} ;
45
21
46
22
// Redirect console.log message from MiniLZ4 to stderr since stdout is
47
23
// where we return the decompressed data.
48
24
console . log = printErr ;
49
25
50
- const lz4 = arguments_ [ 0 ] ;
51
- const input = arguments_ [ 1 ] ;
52
- const output = arguments_ [ 2 ] ;
26
+ const MiniLZ4 = await import ( '../third_party/mini-lz4.js' ) ;
53
27
54
- load ( lz4 ) ;
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 ] ;
55
36
56
37
const data = new Uint8Array ( readBinary ( input ) ) . buffer ;
57
38
const start = Date . now ( ) ;
0 commit comments