WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

6
node_modules/seek-bzip/.npmignore generated vendored Normal file
View File

@ -0,0 +1,6 @@
# Generated by dmn (https://github.com/inikulin/dmn)
.git*
.npmignore
.travis.yml
test/

185
node_modules/seek-bzip/README.md generated vendored Normal file
View File

@ -0,0 +1,185 @@
# seek-bzip
[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6]
`seek-bzip` is a pure-javascript Node.JS module adapted from [node-bzip](https://github.com/skeggse/node-bzip) and before that [antimatter15's pure-javascript bzip2 decoder](https://github.com/antimatter15/bzip2.js). Like these projects, `seek-bzip` only does decompression (see [compressjs](https://github.com/cscott/compressjs) if you need compression code). Unlike those other projects, `seek-bzip` can seek to and decode single blocks from the bzip2 file.
`seek-bzip` primarily decodes buffers into other buffers, synchronously.
With the help of the [fibers](https://github.com/laverdet/node-fibers)
package, it can operate on node streams; see `test/stream.js` for an
example.
## How to Install
```
npm install seek-bzip
```
This package uses
[Typed Arrays](https://developer.mozilla.org/en-US/docs/JavaScript/Typed_arrays), which are present in node.js >= 0.5.5.
## Usage
After compressing some example data into `example.bz2`, the following will recreate that original data and save it to `example`:
```
var Bunzip = require('seek-bzip');
var fs = require('fs');
var compressedData = fs.readFileSync('example.bz2');
var data = Bunzip.decode(compressedData);
fs.writeFileSync('example', data);
```
See the tests in the `tests/` directory for further usage examples.
For uncompressing single blocks of bzip2-compressed data, you will need
an out-of-band index listing the start of each bzip2 block. (Presumably
you generate this at the same time as you index the start of the information
you wish to seek to inside the compressed file.) The `seek-bzip` module
has been designed to be compatible with the C implementation `seek-bzip2`
available from https://bitbucket.org/james_taylor/seek-bzip2. That codebase
contains a `bzip-table` tool which will generate bzip2 block start indices.
There is also a pure-JavaScript `seek-bzip-table` tool in this package's
`bin` directory.
## Documentation
`require('seek-bzip')` returns a `Bunzip` object. It contains three static
methods. The first is a function accepting one or two parameters:
`Bunzip.decode = function(input, [Number expectedSize] or [output], [boolean multistream])`
The `input` argument can be a "stream" object (which must implement the
`readByte` method), or a `Buffer`.
If `expectedSize` is not present, `decodeBzip` simply decodes `input` and
returns the resulting `Buffer`.
If `expectedSize` is present (and numeric), `decodeBzip` will store
the results in a `Buffer` of length `expectedSize`, and throw an error
in the case that the size of the decoded data does not match
`expectedSize`.
If you pass a non-numeric second parameter, it can either be a `Buffer`
object (which must be of the correct length; an error will be thrown if
the size of the decoded data does not match the buffer length) or
a "stream" object (which must implement a `writeByte` method).
The optional third `multistream` parameter, if true, attempts to continue
reading past the end of the bzip2 file. This supports "multistream"
bzip2 files, which are simply multiple bzip2 files concatenated together.
If this argument is true, the input stream must have an `eof` method
which returns true when the end of the input has been reached.
The second exported method is a function accepting two or three parameters:
`Bunzip.decodeBlock = function(input, Number blockStartBits, [Number expectedSize] or [output])`
The `input` and `expectedSize`/`output` parameters are as above.
The `blockStartBits` parameter gives the start of the desired block, in bits.
If passing a stream as the `input` parameter, it must implement the
`seek` method.
The final exported method is a function accepting two or three parameters:
`Bunzip.table = function(input, Function callback, [boolean multistream])`
The `input` and `multistream` parameters are identical to those for the
`decode` method.
This function will invoke `callback(position, size)` once per bzip2 block,
where `position` gives the starting position of the block (in *bits*), and
`size` gives the uncompressed size of the block (in bytes).
This can be used to construct an index allowing direct access to a particular
block inside a bzip2 file, using the `decodeBlock` method.
## Command-line
There are binaries available in bin. The first generates an index of all
the blocks in a bzip2-compressed file:
```
$ bin/seek-bzip-table test/sample4.bz2
32 99981
320555 99981
606348 99981
847568 99981
1089094 99981
1343625 99981
1596228 99981
1843336 99981
2090919 99981
2342106 39019
$
```
The first field is the starting position of the block, in bits, and the
second field is the length of the block, in bytes.
The second binary decodes an arbitrary block of a bzip2 file:
```
$ bin/seek-bunzip -d -b 2342106 test/sample4.bz2 | tail
élan's
émigré
émigré's
émigrés
épée
épée's
épées
étude
étude's
études
$
```
Use `--help` to see other options.
## Help wanted
Improvements to this module would be generally useful.
Feel free to fork on github and submit pull requests!
## Related projects
* https://github.com/skeggse/node-bzip node-bzip (original upstream source)
* https://github.com/cscott/compressjs
Lots of compression/decompression algorithms from the same author as this
module, including bzip2 compression code.
* https://github.com/cscott/lzjb fast LZJB compression/decompression
## License
#### MIT License
> Copyright © 2013-2015 C. Scott Ananian
>
> Copyright © 2012-2015 Eli Skeggs
>
> Copyright © 2011 Kevin Kwok
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[1]: https://travis-ci.org/cscott/seek-bzip.png
[2]: https://travis-ci.org/cscott/seek-bzip
[3]: https://david-dm.org/cscott/seek-bzip.png
[4]: https://david-dm.org/cscott/seek-bzip
[5]: https://david-dm.org/cscott/seek-bzip/dev-status.png
[6]: https://david-dm.org/cscott/seek-bzip#info=devDependencies

129
node_modules/seek-bzip/bin/seek-bunzip generated vendored Executable file
View File

@ -0,0 +1,129 @@
#!/usr/bin/env node
var program = require('commander');
var Bunzip = require('../');
var fs = require('fs');
program
.version(Bunzip.version)
.usage('-d|-z [infile] [outfile]')
.option('-d, --decompress',
'Decompress stdin to stdout')
//.option('-z, --compress',
// 'Compress stdin to stdout')
.option('-b, --block <n>',
'Extract a single block, starting at <n> bits.', undefined)
.option('-m, --multistream',
'Read a multistream bzip2 file');
program.on('--help', function() {
console.log(' If <infile> is omitted, reads from stdin.');
console.log(' If <outfile> is omitted, writes to stdout.');
});
program.parse(process.argv);
if (!program.compress) { program.decompress = true; }
if (program.compress && program.block !== undefined) {
console.error('--block can only be used with decompression');
return 1;
}
if (program.decompress && program.compress) {
console.error('Must specify either -d or -z.');
return 1;
}
var makeInStream = function(in_fd) {
var stat = fs.fstatSync(in_fd);
var stream = {
buffer: new Buffer(4096),
filePos: null,
pos: 0,
end: 0,
_fillBuffer: function() {
this.end = fs.readSync(in_fd, this.buffer, 0, this.buffer.length,
this.filePos);
this.pos = 0;
if (this.filePos !== null && this.end > 0) {
this.filePos += this.end;
}
},
readByte: function() {
if (this.pos >= this.end) { this._fillBuffer(); }
if (this.pos < this.end) {
return this.buffer[this.pos++];
}
return -1;
},
read: function(buffer, bufOffset, length) {
if (this.pos >= this.end) { this._fillBuffer(); }
var bytesRead = 0;
while (bytesRead < length && this.pos < this.end) {
buffer[bufOffset++] = this.buffer[this.pos++];
bytesRead++;
}
return bytesRead;
},
seek: function(seek_pos) {
this.filePos = seek_pos;
this.pos = this.end = 0;
},
eof: function() {
if (this.pos >= this.end) { this._fillBuffer(); }
return !(this.pos < this.end);
}
};
if (stat.size) {
stream.size = stat.size;
}
return stream;
};
var makeOutStream = function(out_fd) {
return {
buffer: new Buffer(4096),
pos: 0,
flush: function() {
fs.writeSync(out_fd, this.buffer, 0, this.pos);
this.pos = 0;
},
writeByte: function(byte) {
if (this.pos >= this.buffer.length) { this.flush(); }
this.buffer[this.pos++] = byte;
}
};
};
var in_fd = 0, close_in = function(){};
var out_fd = 1, close_out = function(){};
if (program.args.length > 0) {
in_fd = fs.openSync(program.args.shift(), 'r');
close_in = function() { fs.closeSync(in_fd); };
}
if (program.args.length > 0) {
out_fd = fs.openSync(program.args.shift(), 'w');
close_out = function() { fs.closeSync(out_fd); };
}
var inStream = makeInStream(in_fd);
var outStream= makeOutStream(out_fd);
if (program.decompress) {
try {
if (program.block !== undefined) {
Bunzip.decodeBlock(inStream, +program.block, outStream);
} else {
Bunzip.decode(inStream, outStream, program.multistream);
}
outStream.flush();
} catch (e) {
if (e.code !== 'EPIPE') throw e;
}
close_in();
close_out();
return 0;
}
if (program.compress) {
console.error('Compression not yet implemented.');
return 1;
}
return 1;

71
node_modules/seek-bzip/bin/seek-bzip-table generated vendored Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env node
var program = require('commander');
var Bunzip = require('../');
var fs = require('fs');
program
.version(Bunzip.version)
.usage('[infile]')
.option('-m, --multistream',
'Read a multistream bzip2 file');
program.on('--help', function() {
console.log(' If <infile> is omitted, reads from stdin.');
});
program.parse(process.argv);
var makeInStream = function(in_fd) {
var stat = fs.fstatSync(in_fd);
var stream = {
buffer: new Buffer(4096),
totalPos: 0,
pos: 0,
end: 0,
_fillBuffer: function() {
this.end = fs.readSync(in_fd, this.buffer, 0, this.buffer.length);
this.pos = 0;
},
readByte: function() {
if (this.pos >= this.end) { this._fillBuffer(); }
if (this.pos < this.end) {
this.totalPos++;
return this.buffer[this.pos++];
}
return -1;
},
read: function(buffer, bufOffset, length) {
if (this.pos >= this.end) { this._fillBuffer(); }
var bytesRead = 0;
while (bytesRead < length && this.pos < this.end) {
buffer[bufOffset++] = this.buffer[this.pos++];
bytesRead++;
}
this.totalPos += bytesRead;
return bytesRead;
},
eof: function() {
if (this.pos >= this.end) { this._fillBuffer(); }
return !(this.pos < this.end);
}
};
if (stat.size) {
stream.size = stat.size;
}
return stream;
};
var in_fd = 0, close_in = function(){};
if (program.args.length > 0) {
in_fd = fs.openSync(program.args.shift(), 'r');
close_in = function() { fs.closeSync(in_fd); };
}
var inStream = makeInStream(in_fd);
var report = function(position, blocksize) {
console.log(position+'\t'+blocksize);
};
Bunzip.table(inStream, report, program.multistream);
close_in();
return 0;

89
node_modules/seek-bzip/lib/bitreader.js generated vendored Normal file
View File

@ -0,0 +1,89 @@
/*
node-bzip - a pure-javascript Node.JS module for decoding bzip2 data
Copyright (C) 2012 Eli Skeggs
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see
http://www.gnu.org/licenses/lgpl-2.1.html
Adapted from bzip2.js, copyright 2011 antimatter15 (antimatter15@gmail.com).
Based on micro-bunzip by Rob Landley (rob@landley.net).
Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
which also acknowledges contributions by Mike Burrows, David Wheeler,
Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
Robert Sedgewick, and Jon L. Bentley.
*/
var BITMASK = [0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF];
// offset in bytes
var BitReader = function(stream) {
this.stream = stream;
this.bitOffset = 0;
this.curByte = 0;
this.hasByte = false;
};
BitReader.prototype._ensureByte = function() {
if (!this.hasByte) {
this.curByte = this.stream.readByte();
this.hasByte = true;
}
};
// reads bits from the buffer
BitReader.prototype.read = function(bits) {
var result = 0;
while (bits > 0) {
this._ensureByte();
var remaining = 8 - this.bitOffset;
// if we're in a byte
if (bits >= remaining) {
result <<= remaining;
result |= BITMASK[remaining] & this.curByte;
this.hasByte = false;
this.bitOffset = 0;
bits -= remaining;
} else {
result <<= bits;
var shift = remaining - bits;
result |= (this.curByte & (BITMASK[bits] << shift)) >> shift;
this.bitOffset += bits;
bits = 0;
}
}
return result;
};
// seek to an arbitrary point in the buffer (expressed in bits)
BitReader.prototype.seek = function(pos) {
var n_bit = pos % 8;
var n_byte = (pos - n_bit) / 8;
this.bitOffset = n_bit;
this.stream.seek(n_byte);
this.hasByte = false;
};
// reads 6 bytes worth of data using the read method
BitReader.prototype.pi = function() {
var buf = new Buffer(6), i;
for (i = 0; i < buf.length; i++) {
buf[i] = this.read(8);
}
return buf.toString('hex');
};
module.exports = BitReader;

104
node_modules/seek-bzip/lib/crc32.js generated vendored Normal file
View File

@ -0,0 +1,104 @@
/* CRC32, used in Bzip2 implementation.
* This is a port of CRC32.java from the jbzip2 implementation at
* https://code.google.com/p/jbzip2
* which is:
* Copyright (c) 2011 Matthew Francis
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
* This JavaScript implementation is:
* Copyright (c) 2013 C. Scott Ananian
* with the same licensing terms as Matthew Francis' original implementation.
*/
module.exports = (function() {
/**
* A static CRC lookup table
*/
var crc32Lookup = new Uint32Array([
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
]);
var CRC32 = function() {
/**
* The current CRC
*/
var crc = 0xffffffff;
/**
* @return The current CRC
*/
this.getCRC = function() {
return (~crc) >>> 0; // return an unsigned value
};
/**
* Update the CRC with a single byte
* @param value The value to update the CRC with
*/
this.updateCRC = function(value) {
crc = (crc << 8) ^ crc32Lookup[((crc >>> 24) ^ value) & 0xff];
};
/**
* Update the CRC with a sequence of identical bytes
* @param value The value to update the CRC with
* @param count The number of bytes
*/
this.updateCRCRun = function(value, count) {
while (count-- > 0) {
crc = (crc << 8) ^ crc32Lookup[((crc >>> 24) ^ value) & 0xff];
}
};
};
return CRC32;
})();

600
node_modules/seek-bzip/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,600 @@
/*
seek-bzip - a pure-javascript module for seeking within bzip2 data
Copyright (C) 2013 C. Scott Ananian
Copyright (C) 2012 Eli Skeggs
Copyright (C) 2011 Kevin Kwok
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see
http://www.gnu.org/licenses/lgpl-2.1.html
Adapted from node-bzip, copyright 2012 Eli Skeggs.
Adapted from bzip2.js, copyright 2011 Kevin Kwok (antimatter15@gmail.com).
Based on micro-bunzip by Rob Landley (rob@landley.net).
Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
which also acknowledges contributions by Mike Burrows, David Wheeler,
Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
Robert Sedgewick, and Jon L. Bentley.
*/
var BitReader = require('./bitreader');
var Stream = require('./stream');
var CRC32 = require('./crc32');
var pjson = require('../package.json');
var MAX_HUFCODE_BITS = 20;
var MAX_SYMBOLS = 258;
var SYMBOL_RUNA = 0;
var SYMBOL_RUNB = 1;
var MIN_GROUPS = 2;
var MAX_GROUPS = 6;
var GROUP_SIZE = 50;
var WHOLEPI = "314159265359";
var SQRTPI = "177245385090";
var mtf = function(array, index) {
var src = array[index], i;
for (i = index; i > 0; i--) {
array[i] = array[i-1];
}
array[0] = src;
return src;
};
var Err = {
OK: 0,
LAST_BLOCK: -1,
NOT_BZIP_DATA: -2,
UNEXPECTED_INPUT_EOF: -3,
UNEXPECTED_OUTPUT_EOF: -4,
DATA_ERROR: -5,
OUT_OF_MEMORY: -6,
OBSOLETE_INPUT: -7,
END_OF_BLOCK: -8
};
var ErrorMessages = {};
ErrorMessages[Err.LAST_BLOCK] = "Bad file checksum";
ErrorMessages[Err.NOT_BZIP_DATA] = "Not bzip data";
ErrorMessages[Err.UNEXPECTED_INPUT_EOF] = "Unexpected input EOF";
ErrorMessages[Err.UNEXPECTED_OUTPUT_EOF] = "Unexpected output EOF";
ErrorMessages[Err.DATA_ERROR] = "Data error";
ErrorMessages[Err.OUT_OF_MEMORY] = "Out of memory";
ErrorMessages[Err.OBSOLETE_INPUT] = "Obsolete (pre 0.9.5) bzip format not supported.";
var _throw = function(status, optDetail) {
var msg = ErrorMessages[status] || 'unknown error';
if (optDetail) { msg += ': '+optDetail; }
var e = new TypeError(msg);
e.errorCode = status;
throw e;
};
var Bunzip = function(inputStream, outputStream) {
this.writePos = this.writeCurrent = this.writeCount = 0;
this._start_bunzip(inputStream, outputStream);
};
Bunzip.prototype._init_block = function() {
var moreBlocks = this._get_next_block();
if ( !moreBlocks ) {
this.writeCount = -1;
return false; /* no more blocks */
}
this.blockCRC = new CRC32();
return true;
};
/* XXX micro-bunzip uses (inputStream, inputBuffer, len) as arguments */
Bunzip.prototype._start_bunzip = function(inputStream, outputStream) {
/* Ensure that file starts with "BZh['1'-'9']." */
var buf = new Buffer(4);
if (inputStream.read(buf, 0, 4) !== 4 ||
String.fromCharCode(buf[0], buf[1], buf[2]) !== 'BZh')
_throw(Err.NOT_BZIP_DATA, 'bad magic');
var level = buf[3] - 0x30;
if (level < 1 || level > 9)
_throw(Err.NOT_BZIP_DATA, 'level out of range');
this.reader = new BitReader(inputStream);
/* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
uncompressed data. Allocate intermediate buffer for block. */
this.dbufSize = 100000 * level;
this.nextoutput = 0;
this.outputStream = outputStream;
this.streamCRC = 0;
};
Bunzip.prototype._get_next_block = function() {
var i, j, k;
var reader = this.reader;
// this is get_next_block() function from micro-bunzip:
/* Read in header signature and CRC, then validate signature.
(last block signature means CRC is for whole file, return now) */
var h = reader.pi();
if (h === SQRTPI) { // last block
return false; /* no more blocks */
}
if (h !== WHOLEPI)
_throw(Err.NOT_BZIP_DATA);
this.targetBlockCRC = reader.read(32) >>> 0; // (convert to unsigned)
this.streamCRC = (this.targetBlockCRC ^
((this.streamCRC << 1) | (this.streamCRC>>>31))) >>> 0;
/* We can add support for blockRandomised if anybody complains. There was
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
it didn't actually work. */
if (reader.read(1))
_throw(Err.OBSOLETE_INPUT);
var origPointer = reader.read(24);
if (origPointer > this.dbufSize)
_throw(Err.DATA_ERROR, 'initial position out of bounds');
/* mapping table: if some byte values are never used (encoding things
like ascii text), the compression code removes the gaps to have fewer
symbols to deal with, and writes a sparse bitfield indicating which
values were present. We make a translation table to convert the symbols
back to the corresponding bytes. */
var t = reader.read(16);
var symToByte = new Buffer(256), symTotal = 0;
for (i = 0; i < 16; i++) {
if (t & (1 << (0xF - i))) {
var o = i * 16;
k = reader.read(16);
for (j = 0; j < 16; j++)
if (k & (1 << (0xF - j)))
symToByte[symTotal++] = o + j;
}
}
/* How many different huffman coding groups does this block use? */
var groupCount = reader.read(3);
if (groupCount < MIN_GROUPS || groupCount > MAX_GROUPS)
_throw(Err.DATA_ERROR);
/* nSelectors: Every GROUP_SIZE many symbols we select a new huffman coding
group. Read in the group selector list, which is stored as MTF encoded
bit runs. (MTF=Move To Front, as each value is used it's moved to the
start of the list.) */
var nSelectors = reader.read(15);
if (nSelectors === 0)
_throw(Err.DATA_ERROR);
var mtfSymbol = new Buffer(256);
for (i = 0; i < groupCount; i++)
mtfSymbol[i] = i;
var selectors = new Buffer(nSelectors); // was 32768...
for (i = 0; i < nSelectors; i++) {
/* Get next value */
for (j = 0; reader.read(1); j++)
if (j >= groupCount) _throw(Err.DATA_ERROR);
/* Decode MTF to get the next selector */
selectors[i] = mtf(mtfSymbol, j);
}
/* Read the huffman coding tables for each group, which code for symTotal
literal symbols, plus two run symbols (RUNA, RUNB) */
var symCount = symTotal + 2;
var groups = [], hufGroup;
for (j = 0; j < groupCount; j++) {
var length = new Buffer(symCount), temp = new Uint16Array(MAX_HUFCODE_BITS + 1);
/* Read huffman code lengths for each symbol. They're stored in
a way similar to mtf; record a starting value for the first symbol,
and an offset from the previous value for everys symbol after that. */
t = reader.read(5); // lengths
for (i = 0; i < symCount; i++) {
for (;;) {
if (t < 1 || t > MAX_HUFCODE_BITS) _throw(Err.DATA_ERROR);
/* If first bit is 0, stop. Else second bit indicates whether
to increment or decrement the value. */
if(!reader.read(1))
break;
if(!reader.read(1))
t++;
else
t--;
}
length[i] = t;
}
/* Find largest and smallest lengths in this group */
var minLen, maxLen;
minLen = maxLen = length[0];
for (i = 1; i < symCount; i++) {
if (length[i] > maxLen)
maxLen = length[i];
else if (length[i] < minLen)
minLen = length[i];
}
/* Calculate permute[], base[], and limit[] tables from length[].
*
* permute[] is the lookup table for converting huffman coded symbols
* into decoded symbols. base[] is the amount to subtract from the
* value of a huffman symbol of a given length when using permute[].
*
* limit[] indicates the largest numerical value a symbol with a given
* number of bits can have. This is how the huffman codes can vary in
* length: each code with a value>limit[length] needs another bit.
*/
hufGroup = {};
groups.push(hufGroup);
hufGroup.permute = new Uint16Array(MAX_SYMBOLS);
hufGroup.limit = new Uint32Array(MAX_HUFCODE_BITS + 2);
hufGroup.base = new Uint32Array(MAX_HUFCODE_BITS + 1);
hufGroup.minLen = minLen;
hufGroup.maxLen = maxLen;
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
var pp = 0;
for (i = minLen; i <= maxLen; i++) {
temp[i] = hufGroup.limit[i] = 0;
for (t = 0; t < symCount; t++)
if (length[t] === i)
hufGroup.permute[pp++] = t;
}
/* Count symbols coded for at each bit length */
for (i = 0; i < symCount; i++)
temp[length[i]]++;
/* Calculate limit[] (the largest symbol-coding value at each bit
* length, which is (previous limit<<1)+symbols at this level), and
* base[] (number of symbols to ignore at each bit length, which is
* limit minus the cumulative count of symbols coded for already). */
pp = t = 0;
for (i = minLen; i < maxLen; i++) {
pp += temp[i];
/* We read the largest possible symbol size and then unget bits
after determining how many we need, and those extra bits could
be set to anything. (They're noise from future symbols.) At
each level we're really only interested in the first few bits,
so here we set all the trailing to-be-ignored bits to 1 so they
don't affect the value>limit[length] comparison. */
hufGroup.limit[i] = pp - 1;
pp <<= 1;
t += temp[i];
hufGroup.base[i + 1] = pp - t;
}
hufGroup.limit[maxLen + 1] = Number.MAX_VALUE; /* Sentinal value for reading next sym. */
hufGroup.limit[maxLen] = pp + temp[maxLen] - 1;
hufGroup.base[minLen] = 0;
}
/* We've finished reading and digesting the block header. Now read this
block's huffman coded symbols from the file and undo the huffman coding
and run length encoding, saving the result into dbuf[dbufCount++]=uc */
/* Initialize symbol occurrence counters and symbol Move To Front table */
var byteCount = new Uint32Array(256);
for (i = 0; i < 256; i++)
mtfSymbol[i] = i;
/* Loop through compressed symbols. */
var runPos = 0, dbufCount = 0, selector = 0, uc;
var dbuf = this.dbuf = new Uint32Array(this.dbufSize);
symCount = 0;
for (;;) {
/* Determine which huffman coding group to use. */
if (!(symCount--)) {
symCount = GROUP_SIZE - 1;
if (selector >= nSelectors) { _throw(Err.DATA_ERROR); }
hufGroup = groups[selectors[selector++]];
}
/* Read next huffman-coded symbol. */
i = hufGroup.minLen;
j = reader.read(i);
for (;;i++) {
if (i > hufGroup.maxLen) { _throw(Err.DATA_ERROR); }
if (j <= hufGroup.limit[i])
break;
j = (j << 1) | reader.read(1);
}
/* Huffman decode value to get nextSym (with bounds checking) */
j -= hufGroup.base[i];
if (j < 0 || j >= MAX_SYMBOLS) { _throw(Err.DATA_ERROR); }
var nextSym = hufGroup.permute[j];
/* We have now decoded the symbol, which indicates either a new literal
byte, or a repeated run of the most recent literal byte. First,
check if nextSym indicates a repeated run, and if so loop collecting
how many times to repeat the last literal. */
if (nextSym === SYMBOL_RUNA || nextSym === SYMBOL_RUNB) {
/* If this is the start of a new run, zero out counter */
if (!runPos){
runPos = 1;
t = 0;
}
/* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at
each bit position, add 1 or 2 instead. For example,
1011 is 1<<0 + 1<<1 + 2<<2. 1010 is 2<<0 + 2<<1 + 1<<2.
You can make any bit pattern that way using 1 less symbol than
the basic or 0/1 method (except all bits 0, which would use no
symbols, but a run of length 0 doesn't mean anything in this
context). Thus space is saved. */
if (nextSym === SYMBOL_RUNA)
t += runPos;
else
t += 2 * runPos;
runPos <<= 1;
continue;
}
/* When we hit the first non-run symbol after a run, we now know
how many times to repeat the last literal, so append that many
copies to our buffer of decoded symbols (dbuf) now. (The last
literal used is the one at the head of the mtfSymbol array.) */
if (runPos){
runPos = 0;
if (dbufCount + t > this.dbufSize) { _throw(Err.DATA_ERROR); }
uc = symToByte[mtfSymbol[0]];
byteCount[uc] += t;
while (t--)
dbuf[dbufCount++] = uc;
}
/* Is this the terminating symbol? */
if (nextSym > symTotal)
break;
/* At this point, nextSym indicates a new literal character. Subtract
one to get the position in the MTF array at which this literal is
currently to be found. (Note that the result can't be -1 or 0,
because 0 and 1 are RUNA and RUNB. But another instance of the
first symbol in the mtf array, position 0, would have been handled
as part of a run above. Therefore 1 unused mtf position minus
2 non-literal nextSym values equals -1.) */
if (dbufCount >= this.dbufSize) { _throw(Err.DATA_ERROR); }
i = nextSym - 1;
uc = mtf(mtfSymbol, i);
uc = symToByte[uc];
/* We have our literal byte. Save it into dbuf. */
byteCount[uc]++;
dbuf[dbufCount++] = uc;
}
/* At this point, we've read all the huffman-coded symbols (and repeated
runs) for this block from the input stream, and decoded them into the
intermediate buffer. There are dbufCount many decoded bytes in dbuf[].
Now undo the Burrows-Wheeler transform on dbuf.
See http://dogma.net/markn/articles/bwt/bwt.htm
*/
if (origPointer < 0 || origPointer >= dbufCount) { _throw(Err.DATA_ERROR); }
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
j = 0;
for (i = 0; i < 256; i++) {
k = j + byteCount[i];
byteCount[i] = j;
j = k;
}
/* Figure out what order dbuf would be in if we sorted it. */
for (i = 0; i < dbufCount; i++) {
uc = dbuf[i] & 0xff;
dbuf[byteCount[uc]] |= (i << 8);
byteCount[uc]++;
}
/* Decode first byte by hand to initialize "previous" byte. Note that it
doesn't get output, and if the first three characters are identical
it doesn't qualify as a run (hence writeRunCountdown=5). */
var pos = 0, current = 0, run = 0;
if (dbufCount) {
pos = dbuf[origPointer];
current = (pos & 0xff);
pos >>= 8;
run = -1;
}
this.writePos = pos;
this.writeCurrent = current;
this.writeCount = dbufCount;
this.writeRun = run;
return true; /* more blocks to come */
};
/* Undo burrows-wheeler transform on intermediate buffer to produce output.
If start_bunzip was initialized with out_fd=-1, then up to len bytes of
data are written to outbuf. Return value is number of bytes written or
error (all errors are negative numbers). If out_fd!=-1, outbuf and len
are ignored, data is written to out_fd and return is RETVAL_OK or error.
*/
Bunzip.prototype._read_bunzip = function(outputBuffer, len) {
var copies, previous, outbyte;
/* james@jamestaylor.org: writeCount goes to -1 when the buffer is fully
decoded, which results in this returning RETVAL_LAST_BLOCK, also
equal to -1... Confusing, I'm returning 0 here to indicate no
bytes written into the buffer */
if (this.writeCount < 0) { return 0; }
var gotcount = 0;
var dbuf = this.dbuf, pos = this.writePos, current = this.writeCurrent;
var dbufCount = this.writeCount, outputsize = this.outputsize;
var run = this.writeRun;
while (dbufCount) {
dbufCount--;
previous = current;
pos = dbuf[pos];
current = pos & 0xff;
pos >>= 8;
if (run++ === 3){
copies = current;
outbyte = previous;
current = -1;
} else {
copies = 1;
outbyte = current;
}
this.blockCRC.updateCRCRun(outbyte, copies);
while (copies--) {
this.outputStream.writeByte(outbyte);
this.nextoutput++;
}
if (current != previous)
run = 0;
}
this.writeCount = dbufCount;
// check CRC
if (this.blockCRC.getCRC() !== this.targetBlockCRC) {
_throw(Err.DATA_ERROR, "Bad block CRC "+
"(got "+this.blockCRC.getCRC().toString(16)+
" expected "+this.targetBlockCRC.toString(16)+")");
}
return this.nextoutput;
};
var coerceInputStream = function(input) {
if ('readByte' in input) { return input; }
var inputStream = new Stream();
inputStream.pos = 0;
inputStream.readByte = function() { return input[this.pos++]; };
inputStream.seek = function(pos) { this.pos = pos; };
inputStream.eof = function() { return this.pos >= input.length; };
return inputStream;
};
var coerceOutputStream = function(output) {
var outputStream = new Stream();
var resizeOk = true;
if (output) {
if (typeof(output)==='number') {
outputStream.buffer = new Buffer(output);
resizeOk = false;
} else if ('writeByte' in output) {
return output;
} else {
outputStream.buffer = output;
resizeOk = false;
}
} else {
outputStream.buffer = new Buffer(16384);
}
outputStream.pos = 0;
outputStream.writeByte = function(_byte) {
if (resizeOk && this.pos >= this.buffer.length) {
var newBuffer = new Buffer(this.buffer.length*2);
this.buffer.copy(newBuffer);
this.buffer = newBuffer;
}
this.buffer[this.pos++] = _byte;
};
outputStream.getBuffer = function() {
// trim buffer
if (this.pos !== this.buffer.length) {
if (!resizeOk)
throw new TypeError('outputsize does not match decoded input');
var newBuffer = new Buffer(this.pos);
this.buffer.copy(newBuffer, 0, 0, this.pos);
this.buffer = newBuffer;
}
return this.buffer;
};
outputStream._coerced = true;
return outputStream;
};
/* Static helper functions */
Bunzip.Err = Err;
// 'input' can be a stream or a buffer
// 'output' can be a stream or a buffer or a number (buffer size)
Bunzip.decode = function(input, output, multistream) {
// make a stream from a buffer, if necessary
var inputStream = coerceInputStream(input);
var outputStream = coerceOutputStream(output);
var bz = new Bunzip(inputStream, outputStream);
while (true) {
if ('eof' in inputStream && inputStream.eof()) break;
if (bz._init_block()) {
bz._read_bunzip();
} else {
var targetStreamCRC = bz.reader.read(32) >>> 0; // (convert to unsigned)
if (targetStreamCRC !== bz.streamCRC) {
_throw(Err.DATA_ERROR, "Bad stream CRC "+
"(got "+bz.streamCRC.toString(16)+
" expected "+targetStreamCRC.toString(16)+")");
}
if (multistream &&
'eof' in inputStream &&
!inputStream.eof()) {
// note that start_bunzip will also resync the bit reader to next byte
bz._start_bunzip(inputStream, outputStream);
} else break;
}
}
if ('getBuffer' in outputStream)
return outputStream.getBuffer();
};
Bunzip.decodeBlock = function(input, pos, output) {
// make a stream from a buffer, if necessary
var inputStream = coerceInputStream(input);
var outputStream = coerceOutputStream(output);
var bz = new Bunzip(inputStream, outputStream);
bz.reader.seek(pos);
/* Fill the decode buffer for the block */
var moreBlocks = bz._get_next_block();
if (moreBlocks) {
/* Init the CRC for writing */
bz.blockCRC = new CRC32();
/* Zero this so the current byte from before the seek is not written */
bz.writeCopies = 0;
/* Decompress the block and write to stdout */
bz._read_bunzip();
// XXX keep writing?
}
if ('getBuffer' in outputStream)
return outputStream.getBuffer();
};
/* Reads bzip2 file from stream or buffer `input`, and invoke
* `callback(position, size)` once for each bzip2 block,
* where position gives the starting position (in *bits*)
* and size gives uncompressed size of the block (in *bytes*). */
Bunzip.table = function(input, callback, multistream) {
// make a stream from a buffer, if necessary
var inputStream = new Stream();
inputStream.delegate = coerceInputStream(input);
inputStream.pos = 0;
inputStream.readByte = function() {
this.pos++;
return this.delegate.readByte();
};
if (inputStream.delegate.eof) {
inputStream.eof = inputStream.delegate.eof.bind(inputStream.delegate);
}
var outputStream = new Stream();
outputStream.pos = 0;
outputStream.writeByte = function() { this.pos++; };
var bz = new Bunzip(inputStream, outputStream);
var blockSize = bz.dbufSize;
while (true) {
if ('eof' in inputStream && inputStream.eof()) break;
var position = inputStream.pos*8 + bz.reader.bitOffset;
if (bz.reader.hasByte) { position -= 8; }
if (bz._init_block()) {
var start = outputStream.pos;
bz._read_bunzip();
callback(position, outputStream.pos - start);
} else {
var crc = bz.reader.read(32); // (but we ignore the crc)
if (multistream &&
'eof' in inputStream &&
!inputStream.eof()) {
// note that start_bunzip will also resync the bit reader to next byte
bz._start_bunzip(inputStream, outputStream);
console.assert(bz.dbufSize === blockSize,
"shouldn't change block size within multistream file");
} else break;
}
}
};
Bunzip.Stream = Stream;
Bunzip.version = pjson.version;
Bunzip.license = pjson.license;
module.exports = Bunzip;

42
node_modules/seek-bzip/lib/stream.js generated vendored Normal file
View File

@ -0,0 +1,42 @@
/* very simple input/output stream interface */
var Stream = function() {
};
// input streams //////////////
/** Returns the next byte, or -1 for EOF. */
Stream.prototype.readByte = function() {
throw new Error("abstract method readByte() not implemented");
};
/** Attempts to fill the buffer; returns number of bytes read, or
* -1 for EOF. */
Stream.prototype.read = function(buffer, bufOffset, length) {
var bytesRead = 0;
while (bytesRead < length) {
var c = this.readByte();
if (c < 0) { // EOF
return (bytesRead===0) ? -1 : bytesRead;
}
buffer[bufOffset++] = c;
bytesRead++;
}
return bytesRead;
};
Stream.prototype.seek = function(new_pos) {
throw new Error("abstract method seek() not implemented");
};
// output streams ///////////
Stream.prototype.writeByte = function(_byte) {
throw new Error("abstract method readByte() not implemented");
};
Stream.prototype.write = function(buffer, bufOffset, length) {
var i;
for (i=0; i<length; i++) {
this.writeByte(buffer[bufOffset++]);
}
return length;
};
Stream.prototype.flush = function() {
};
module.exports = Stream;

View File

@ -0,0 +1,256 @@
2.8.1 / 2015-04-22
==================
* Back out `support multiline description` Close #396 #397
2.8.0 / 2015-04-07
==================
* Add `process.execArg` support, execution args like `--harmony` will be passed to sub-commands #387 @DigitalIO @zhiyelee
* Fix bug in Git-style sub-commands #372 @zhiyelee
* Allow commands to be hidden from help #383 @tonylukasavage
* When git-style sub-commands are in use, yet none are called, display help #382 @claylo
* Add ability to specify arguments syntax for top-level command #258 @rrthomas
* Support multiline descriptions #208 @zxqfox
2.7.1 / 2015-03-11
==================
* Revert #347 (fix collisions when option and first arg have same name) which causes a bug in #367.
2.7.0 / 2015-03-09
==================
* Fix git-style bug when installed globally. Close #335 #349 @zhiyelee
* Fix collisions when option and first arg have same name. Close #346 #347 @tonylukasavage
* Add support for camelCase on `opts()`. Close #353 @nkzawa
* Add node.js 0.12 and io.js to travis.yml
* Allow RegEx options. #337 @palanik
* Fixes exit code when sub-command failing. Close #260 #332 @pirelenito
* git-style `bin` files in $PATH make sense. Close #196 #327 @zhiyelee
2.6.0 / 2014-12-30
==================
* added `Command#allowUnknownOption` method. Close #138 #318 @doozr @zhiyelee
* Add application description to the help msg. Close #112 @dalssoft
2.5.1 / 2014-12-15
==================
* fixed two bugs incurred by variadic arguments. Close #291 @Quentin01 #302 @zhiyelee
2.5.0 / 2014-10-24
==================
* add support for variadic arguments. Closes #277 @whitlockjc
2.4.0 / 2014-10-17
==================
* fixed a bug on executing the coercion function of subcommands option. Closes #270
* added `Command.prototype.name` to retrieve command name. Closes #264 #266 @tonylukasavage
* added `Command.prototype.opts` to retrieve all the options as a simple object of key-value pairs. Closes #262 @tonylukasavage
* fixed a bug on subcommand name. Closes #248 @jonathandelgado
* fixed function normalize doesnt honor option terminator. Closes #216 @abbr
2.3.0 / 2014-07-16
==================
* add command alias'. Closes PR #210
* fix: Typos. Closes #99
* fix: Unused fs module. Closes #217
2.2.0 / 2014-03-29
==================
* add passing of previous option value
* fix: support subcommands on windows. Closes #142
* Now the defaultValue passed as the second argument of the coercion function.
2.1.0 / 2013-11-21
==================
* add: allow cflag style option params, unit test, fixes #174
2.0.0 / 2013-07-18
==================
* remove input methods (.prompt, .confirm, etc)
1.3.2 / 2013-07-18
==================
* add support for sub-commands to co-exist with the original command
1.3.1 / 2013-07-18
==================
* add quick .runningCommand hack so you can opt-out of other logic when running a sub command
1.3.0 / 2013-07-09
==================
* add EACCES error handling
* fix sub-command --help
1.2.0 / 2013-06-13
==================
* allow "-" hyphen as an option argument
* support for RegExp coercion
1.1.1 / 2012-11-20
==================
* add more sub-command padding
* fix .usage() when args are present. Closes #106
1.1.0 / 2012-11-16
==================
* add git-style executable subcommand support. Closes #94
1.0.5 / 2012-10-09
==================
* fix `--name` clobbering. Closes #92
* fix examples/help. Closes #89
1.0.4 / 2012-09-03
==================
* add `outputHelp()` method.
1.0.3 / 2012-08-30
==================
* remove invalid .version() defaulting
1.0.2 / 2012-08-24
==================
* add `--foo=bar` support [arv]
* fix password on node 0.8.8. Make backward compatible with 0.6 [focusaurus]
1.0.1 / 2012-08-03
==================
* fix issue #56
* fix tty.setRawMode(mode) was moved to tty.ReadStream#setRawMode() (i.e. process.stdin.setRawMode())
1.0.0 / 2012-07-05
==================
* add support for optional option descriptions
* add defaulting of `.version()` to package.json's version
0.6.1 / 2012-06-01
==================
* Added: append (yes or no) on confirmation
* Added: allow node.js v0.7.x
0.6.0 / 2012-04-10
==================
* Added `.prompt(obj, callback)` support. Closes #49
* Added default support to .choose(). Closes #41
* Fixed the choice example
0.5.1 / 2011-12-20
==================
* Fixed `password()` for recent nodes. Closes #36
0.5.0 / 2011-12-04
==================
* Added sub-command option support [itay]
0.4.3 / 2011-12-04
==================
* Fixed custom help ordering. Closes #32
0.4.2 / 2011-11-24
==================
* Added travis support
* Fixed: line-buffered input automatically trimmed. Closes #31
0.4.1 / 2011-11-18
==================
* Removed listening for "close" on --help
0.4.0 / 2011-11-15
==================
* Added support for `--`. Closes #24
0.3.3 / 2011-11-14
==================
* Fixed: wait for close event when writing help info [Jerry Hamlet]
0.3.2 / 2011-11-01
==================
* Fixed long flag definitions with values [felixge]
0.3.1 / 2011-10-31
==================
* Changed `--version` short flag to `-V` from `-v`
* Changed `.version()` so it's configurable [felixge]
0.3.0 / 2011-10-31
==================
* Added support for long flags only. Closes #18
0.2.1 / 2011-10-24
==================
* "node": ">= 0.4.x < 0.7.0". Closes #20
0.2.0 / 2011-09-26
==================
* Allow for defaults that are not just boolean. Default peassignment only occurs for --no-*, optional, and required arguments. [Jim Isaacs]
0.1.0 / 2011-08-24
==================
* Added support for custom `--help` output
0.0.5 / 2011-08-18
==================
* Changed: when the user enters nothing prompt for password again
* Fixed issue with passwords beginning with numbers [NuckChorris]
0.0.4 / 2011-08-15
==================
* Fixed `Commander#args`
0.0.3 / 2011-08-15
==================
* Added default option value support
0.0.2 / 2011-08-15
==================
* Added mask support to `Command#password(str[, mask], fn)`
* Added `Command#password(str, fn)`
0.0.1 / 2010-01-03
==================
* Initial release

22
node_modules/seek-bzip/node_modules/commander/LICENSE generated vendored Normal file
View File

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

342
node_modules/seek-bzip/node_modules/commander/Readme.md generated vendored Normal file
View File

@ -0,0 +1,342 @@
# Commander.js
[![Build Status](https://api.travis-ci.org/tj/commander.js.svg)](http://travis-ci.org/tj/commander.js)
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![Join the chat at https://gitter.im/tj/commander.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/tj/commander).
[API documentation](http://tj.github.com/commander.js/)
## Installation
$ npm install commander
## Option parsing
Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.0.1')
.option('-p, --peppers', 'Add peppers')
.option('-P, --pineapple', 'Add pineapple')
.option('-b, --bbq-sauce', 'Add bbq sauce')
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
.parse(process.argv);
console.log('you ordered a pizza with:');
if (program.peppers) console.log(' - peppers');
if (program.pineapple) console.log(' - pineapple');
if (program.bbqSauce) console.log(' - bbq');
console.log(' - %s cheese', program.cheese);
```
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
## Coercion
```js
function range(val) {
return val.split('..').map(Number);
}
function list(val) {
return val.split(',');
}
function collect(val, memo) {
memo.push(val);
return memo;
}
function increaseVerbosity(v, total) {
return total + 1;
}
program
.version('0.0.1')
.usage('[options] <file ...>')
.option('-i, --integer <n>', 'An integer argument', parseInt)
.option('-f, --float <n>', 'A float argument', parseFloat)
.option('-r, --range <a>..<b>', 'A range', range)
.option('-l, --list <items>', 'A list', list)
.option('-o, --optional [value]', 'An optional value')
.option('-c, --collect [value]', 'A repeatable value', collect, [])
.option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
.parse(process.argv);
console.log(' int: %j', program.integer);
console.log(' float: %j', program.float);
console.log(' optional: %j', program.optional);
program.range = program.range || [];
console.log(' range: %j..%j', program.range[0], program.range[1]);
console.log(' list: %j', program.list);
console.log(' collect: %j', program.collect);
console.log(' verbosity: %j', program.verbose);
console.log(' args: %j', program.args);
```
## Regular Expression
```js
program
.version('0.0.1')
.option('-s --size <size>', 'Pizza size', /^(large|medium|small)$/i, 'medium')
.option('-d --drink [drink]', 'Drink', /^(coke|pepsi|izze)$/i)
.parse(process.argv);
console.log(' size: %j', program.size);
console.log(' drink: %j', program.drink);
```
## Variadic arguments
The last argument of a command can be variadic, and only the last argument. To make an argument variadic you have to
append `...` to the argument name. Here is an example:
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.0.1')
.command('rmdir <dir> [otherDirs...]')
.action(function (dir, otherDirs) {
console.log('rmdir %s', dir);
if (otherDirs) {
otherDirs.forEach(function (oDir) {
console.log('rmdir %s', oDir);
});
}
});
program.parse(process.argv);
```
An `Array` is used for the value of a variadic argument. This applies to `program.args` as well as the argument passed
to your action as demonstrated above.
## Specify the argument syntax
```js
#!/usr/bin/env node
var program = require('../');
program
.version('0.0.1')
.arguments('<cmd> [env]')
.action(function (cmd, env) {
cmdValue = cmd;
envValue = env;
});
program.parse(process.argv);
if (typeof cmdValue === 'undefined') {
console.error('no command given!');
process.exit(1);
}
console.log('command:', cmdValue);
console.log('environment:', envValue || "no environment given");
```
## Git-style sub-commands
```js
// file: ./examples/pm
var program = require('..');
program
.version('0.0.1')
.command('install [name]', 'install one or more packages')
.command('search [query]', 'search with optional query')
.command('list', 'list packages installed')
.parse(process.argv);
```
When `.command()` is invoked with a description argument, no `.action(callback)` should be called to handle sub-commands, otherwise there will be an error. This tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools.
The commander will try to search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-command`, like `pm-install`, `pm-search`.
If the program is designed to be installed globally, make sure the executables have proper modes, like `755`.
### `--harmony`
You can enable `--harmony` option in two ways:
* Use `#! /usr/bin/env node --harmony` in the sub-commands scripts. Note some os version dont support this pattern.
* Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning sub-command process.
## Automated --help
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
```
$ ./examples/pizza --help
Usage: pizza [options]
An application for pizzas ordering
Options:
-h, --help output usage information
-V, --version output the version number
-p, --peppers Add peppers
-P, --pineapple Add pineapple
-b, --bbq Add bbq sauce
-c, --cheese <type> Add the specified type of cheese [marble]
-C, --no-cheese You do not want any cheese
```
## Custom help
You can display arbitrary `-h, --help` information
by listening for "--help". Commander will automatically
exit once you are done so that the remainder of your program
does not execute causing undesired behaviours, for example
in the following executable "stuff" will not output when
`--help` is used.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.0.1')
.option('-f, --foo', 'enable some foo')
.option('-b, --bar', 'enable some bar')
.option('-B, --baz', 'enable some baz');
// must be before .parse() since
// node's emit() is immediate
program.on('--help', function(){
console.log(' Examples:');
console.log('');
console.log(' $ custom-help --help');
console.log(' $ custom-help -h');
console.log('');
});
program.parse(process.argv);
console.log('stuff');
```
Yields the following help output when `node script-name.js -h` or `node script-name.js --help` are run:
```
Usage: custom-help [options]
Options:
-h, --help output usage information
-V, --version output the version number
-f, --foo enable some foo
-b, --bar enable some bar
-B, --baz enable some baz
Examples:
$ custom-help --help
$ custom-help -h
```
## .outputHelp()
Output help information without exiting.
If you want to display help by default (e.g. if no command was provided), you can use something like:
```js
var program = require('commander');
program
.version('0.0.1')
.command('getstream [url]', 'get stream URL')
.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
}
```
## .help()
Output help information and exit immediately.
## Examples
```js
var program = require('commander');
program
.version('0.0.1')
.option('-C, --chdir <path>', 'change the working directory')
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
.option('-T, --no-tests', 'ignore test hook')
program
.command('setup [env]')
.description('run setup commands for all envs')
.option("-s, --setup_mode [mode]", "Which setup mode to use")
.action(function(env, options){
var mode = options.setup_mode || "normal";
env = env || 'all';
console.log('setup for %s env(s) with %s mode', env, mode);
});
program
.command('exec <cmd>')
.alias('ex')
.description('execute the given remote cmd')
.option("-e, --exec_mode <mode>", "Which exec mode to use")
.action(function(cmd, options){
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
}).on('--help', function() {
console.log(' Examples:');
console.log();
console.log(' $ deploy exec sequential');
console.log(' $ deploy exec async');
console.log();
});
program
.command('*')
.action(function(env){
console.log('deploying "%s"', env);
});
program.parse(process.argv);
```
More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
## License
MIT

1103
node_modules/seek-bzip/node_modules/commander/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,65 @@
{
"_from": "commander@~2.8.1",
"_id": "commander@2.8.1",
"_inBundle": false,
"_integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=",
"_location": "/seek-bzip/commander",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "commander@~2.8.1",
"name": "commander",
"escapedName": "commander",
"rawSpec": "~2.8.1",
"saveSpec": null,
"fetchSpec": "~2.8.1"
},
"_requiredBy": [
"/seek-bzip"
],
"_resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
"_shasum": "06be367febfda0c330aa1e2a072d3dc9762425d4",
"_spec": "commander@~2.8.1",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/seek-bzip",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
},
"bugs": {
"url": "https://github.com/tj/commander.js/issues"
},
"bundleDependencies": false,
"dependencies": {
"graceful-readlink": ">= 1.0.0"
},
"deprecated": false,
"description": "the complete solution for node.js command-line programs",
"devDependencies": {
"should": ">= 0.0.1",
"sinon": ">= 1.14.1"
},
"engines": {
"node": ">= 0.6.x"
},
"files": [
"index.js"
],
"homepage": "https://github.com/tj/commander.js#readme",
"keywords": [
"command",
"option",
"parser"
],
"license": "MIT",
"main": "index",
"name": "commander",
"repository": {
"type": "git",
"url": "git+https://github.com/tj/commander.js.git"
},
"scripts": {
"test": "make test"
},
"version": "2.8.1"
}

75
node_modules/seek-bzip/package.json generated vendored Normal file
View File

@ -0,0 +1,75 @@
{
"_from": "seek-bzip@^1.0.5",
"_id": "seek-bzip@1.0.5",
"_inBundle": false,
"_integrity": "sha1-z+kXyz0nS8/6x5J1ivUxc+sfq9w=",
"_location": "/seek-bzip",
"_phantomChildren": {
"graceful-readlink": "1.0.1"
},
"_requested": {
"type": "range",
"registry": true,
"raw": "seek-bzip@^1.0.5",
"name": "seek-bzip",
"escapedName": "seek-bzip",
"rawSpec": "^1.0.5",
"saveSpec": null,
"fetchSpec": "^1.0.5"
},
"_requiredBy": [
"/decompress-tarbz2"
],
"_resolved": "https://registry.npmjs.org/seek-bzip/-/seek-bzip-1.0.5.tgz",
"_shasum": "cfe917cb3d274bcffac792758af53173eb1fabdc",
"_spec": "seek-bzip@^1.0.5",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/decompress-tarbz2",
"bin": {
"seek-bunzip": "./bin/seek-bunzip",
"seek-table": "./bin/seek-bzip-table"
},
"bugs": {
"url": "https://github.com/cscott/seek-bzip/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "C. Scott Ananian",
"url": "http://cscott.net"
},
{
"name": "Eli Skeggs"
},
{
"name": "Kevin Kwok"
},
{
"name": "Rob Landley",
"url": "http://landley.net"
}
],
"dependencies": {
"commander": "~2.8.1"
},
"deprecated": false,
"description": "a pure-JavaScript Node.JS module for random-access decoding bzip2 data",
"devDependencies": {
"fibers": "~1.0.6",
"mocha": "~2.2.5"
},
"directories": {
"test": "test"
},
"homepage": "https://github.com/cscott/seek-bzip#readme",
"license": "MIT",
"main": "./lib/index.js",
"name": "seek-bzip",
"repository": {
"type": "git",
"url": "git+https://github.com/cscott/seek-bzip.git"
},
"scripts": {
"test": "mocha"
},
"version": "1.0.5"
}