Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi member / bgzip compatibility #145

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ Inflate.prototype.push = function (data, mode) {

status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */

if (status === c.Z_STREAM_END) {
zlib_inflate.inflateReset(strm);
}

if (status === c.Z_NEED_DICT && dictionary) {
// Convert data if needed
if (typeof dictionary === 'string') {
Expand All @@ -237,7 +241,11 @@ Inflate.prototype.push = function (data, mode) {
}

if (strm.next_out) {
if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
if (
strm.avail_out === 0 ||
(status === c.Z_STREAM_END && strm.avail_in === 0) ||
(strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))
) {

if (this.options.to === 'string') {

Expand Down Expand Up @@ -270,7 +278,7 @@ Inflate.prototype.push = function (data, mode) {
allowBufError = true;
}

} while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
} while (strm.avail_in > 0 || strm.avail_out === 0);

if (status === c.Z_STREAM_END) {
_mode = c.Z_FINISH;
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/gzip-joined
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
0
1
2
3
4
5
6
7
8
910
11
12
13
14
15
16
17
18
19
12 changes: 8 additions & 4 deletions test/gzip_specials.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ describe('Gzip special cases', function () {

it('Read stream with SYNC marks', function () {
var inflator, strm, _in, len, pos = 0, i = 0;
var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-joined.gz'));
var inputData = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-joined.gz'));
var expectedData = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-joined'));
var expectedDataArray = new pako_utils.Buf8(expectedData.length);
pako_utils.arraySet(expectedDataArray, expectedData, 0, expectedData.length, 0);

do {
len = data.length - pos;
len = inputData.length - pos;
_in = new pako_utils.Buf8(len);
pako_utils.arraySet(_in, data, pos, len, 0);
pako_utils.arraySet(_in, inputData, pos, len, 0);

inflator = new pako.Inflate();
strm = inflator.strm;
Expand All @@ -79,7 +82,8 @@ describe('Gzip special cases', function () {
i++;
} while (strm.avail_in);

assert(i === 2, 'invalid blobs count');
assert.equal(i, 1, 'should take it all in one blob');
assert.deepEqual(inflator.result, expectedDataArray, 'inflator produced expected data');
});

});