-
Notifications
You must be signed in to change notification settings - Fork 5
/
bz2.js
executable file
·43 lines (34 loc) · 959 Bytes
/
bz2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
'use strict';
const { readFileSync, writeFileSync } = require('fs');
const argv = require('minimist')(process.argv.slice(2));
const { decompress } = require('.');
const { version } = require('./package');
if (argv.help || argv.h) {
process.stdout.write(`bz2 v${version}
usage: bz2 [flags and files in any order]
-h, --help display this help
-v, --version display software version
-t, --test test compressed file integrity
if no filenames are given, bz2 decompresses from
standard input to standard output.
`);
return;
}
if (argv.v || argv.version) {
process.stdout.write(`bz2 v${version}`);
return;
}
const [input, output] = argv._;
const test = argv.test || argv.t;
let result;
if (input) {
result = decompress(readFileSync(input), test);
} else {
result = decompress(readFileSync(0), test);
}
if (output) {
writeFileSync(output, result);
} else {
process.stdout.write(result);
}