unbzip2-stream
Advanced tools
Comparing version 1.2.5 to 1.3.0
23
index.js
@@ -14,2 +14,3 @@ var through = require('through'); | ||
var bitReader = null; | ||
var streamCRC = null; | ||
@@ -30,6 +31,6 @@ function decompressBlock(push){ | ||
var done = bz2.decompress(bitReader, f, buf, bufsize); | ||
if (done) { | ||
push(null); | ||
//console.error('done'); | ||
streamCRC = bz2.decompress(bitReader, f, buf, bufsize, streamCRC); | ||
if (streamCRC === null) { | ||
// reset for next bzip2 header | ||
blockSize = 0; | ||
return false; | ||
@@ -75,6 +76,5 @@ }else{ | ||
} | ||
while (hasBytes - bitReader.bytesRead + 1 >= ((25000 + 100000 * blockSize) || 4)){ | ||
while (!broken && hasBytes - bitReader.bytesRead + 1 >= ((25000 + 100000 * blockSize) || 4)){ | ||
//console.error('decompressing with', hasBytes - bitReader.bytesRead + 1, 'bytes in buffer'); | ||
if (!done) done = !decompressAndQueue(this); | ||
if (done) break; | ||
decompressAndQueue(this); | ||
} | ||
@@ -84,5 +84,10 @@ }, | ||
//console.error(x,'last compressing with', hasBytes, 'bytes in buffer'); | ||
if (!done) { | ||
while(decompressAndQueue(this)); | ||
while (!broken && hasBytes > bitReader.bytesRead){ | ||
decompressAndQueue(this); | ||
} | ||
if (!broken) { | ||
if (streamCRC !== null) | ||
stream.emit('error', new Error("input stream ended prematurely")); | ||
this.queue(null); | ||
} | ||
} | ||
@@ -89,0 +94,0 @@ ); |
@@ -9,2 +9,7 @@ var BITMASK = [0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF]; | ||
var f = function(n) { | ||
if (n === null && bit != 0) { // align to byte boundary | ||
bit = 0 | ||
byte++; | ||
return; | ||
} | ||
var result = 0; | ||
@@ -17,6 +22,7 @@ while(n > 0) { | ||
var left = 8 - bit; | ||
if (bit === 0 && n > 0) | ||
f.bytesRead++; | ||
if (n >= left) { | ||
result <<= left; | ||
result |= (BITMASK[left] & bytes[byte++]); | ||
f.bytesRead++; | ||
bit = 0; | ||
@@ -33,4 +39,4 @@ n -= left; | ||
}; | ||
f.bytesRead = 1; | ||
f.bytesRead = 0; | ||
return f; | ||
}; |
@@ -163,3 +163,3 @@ /* | ||
//a length at which to stop decompressing and return the output | ||
bzip2.decompress = function(bits, stream, buf, bufsize) { | ||
bzip2.decompress = function(bits, stream, buf, bufsize, streamCRC) { | ||
var MAX_HUFCODE_BITS = 20; | ||
@@ -173,3 +173,9 @@ var MAX_SYMBOLS = 258; | ||
for(var h = '', i = 0; i < 6; i++) h += bits(8).toString(16); | ||
if (h == "177245385090") return true; //last block | ||
if (h == "177245385090") { | ||
var finalCRC = bits(32)|0; | ||
if (finalCRC !== streamCRC) message.Error("Error in bzip2: crc32 do not match"); | ||
// align stream to byte | ||
bits(null); | ||
return null; // reset streamCRC for next call | ||
} | ||
if (h != "314159265359") message.Error("eek not valid bzip data"); | ||
@@ -357,5 +363,8 @@ var crcblock = bits(32)|0; // CRC code | ||
if ((crc|0) != (crcblock|0)) message.Error("Error in bzip2: crc32 do not match"); | ||
return false; | ||
if (streamCRC === null) | ||
streamCRC = 0; | ||
streamCRC = (crc ^ ((streamCRC << 1) | (streamCRC >>> 31))) & 0xFFFFFFFF; | ||
return streamCRC; | ||
} | ||
module.exports = bzip2; |
{ | ||
"name": "unbzip2-stream", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "streaming unbzip2 implementation in pure javascript for node and browsers", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
"scripts": { | ||
"prepare": "browserify -s unbzip2Stream index.js | uglifyjs >> dist/unbzip2-stream.min.js", | ||
"prepare": "mkdir dist && browserify -s unbzip2Stream index.js | uglifyjs >> dist/unbzip2-stream.min.js", | ||
"browser-test": "browserify -t brfs test/simple.js | tape-run2 -b phantomjs", | ||
@@ -18,0 +18,0 @@ "prepare-long-test": "dd if=/dev/urandom of=test/fixtures/vmlinux.bin bs=50x1024x1024 count=2 && cat test/fixtures/vmlinux.bin | bzip2 > test/fixtures/vmlinux.bin.bz2", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105730
784
2
4
1