add a bin tool

This commit is contained in:
Gus 2019-07-01 11:18:28 -05:00 committed by Gus Caplan
parent 45f735dcbc
commit 342be4403b
No known key found for this signature in database
GPG Key ID: F00BD11880E82F0E
4 changed files with 54 additions and 3 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
package-lock.json

View File

@ -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
View 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);
}

View File

@ -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"
}
}