add a bin tool
This commit is contained in:
parent
45f735dcbc
commit
342be4403b
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
package-lock.json
|
@ -15,9 +15,9 @@ Try out the [demo](https://http://sheetjs.com/bz2/demo).
|
||||
|
||||
## API
|
||||
|
||||
### `decompress(data, crc)`
|
||||
### `decompress(data, test)`
|
||||
* `data`: `Uint8Array` - The data to be decompressed.
|
||||
* `crc`: `boolean` - Check data using CRC32. Default: `true`.
|
||||
* `test`: `boolean` - Verify integrity of compressed data. Default: `false`.
|
||||
* **Returns**: `Uint8Array`
|
||||
|
||||
Decompresses `data`.
|
||||
|
43
bz2.js
Executable file
43
bz2.js
Executable file
@ -0,0 +1,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);
|
||||
}
|
@ -6,6 +6,9 @@
|
||||
"directories": {
|
||||
"test": "tests"
|
||||
},
|
||||
"bin": {
|
||||
"bz2": "./bz2.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
@ -18,5 +21,8 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/sheetjs/bz2/issues"
|
||||
},
|
||||
"homepage": "https://github.com/sheetjs/bz2#readme"
|
||||
"homepage": "https://github.com/sheetjs/bz2#readme",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user