Sha256: 2e5be3383270b095b6ca6a1d17dd489741c47f60897aa95b4ecded1884a32101

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

'use strict';
// test unzipping a gzip file that has trailing garbage

const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');

// should ignore trailing null-bytes
let data = Buffer.concat([
  zlib.gzipSync('abc'),
  zlib.gzipSync('def'),
  Buffer(10).fill(0)
]);

assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');

zlib.gunzip(data, common.mustCall((err, result) => {
  assert.ifError(err);
  assert.equal(result, 'abcdef', 'result should match original string');
}));

// if the trailing garbage happens to look like a gzip header, it should
// throw an error.
data = Buffer.concat([
  zlib.gzipSync('abc'),
  zlib.gzipSync('def'),
  Buffer([0x1f, 0x8b, 0xff, 0xff]),
  Buffer(10).fill(0)
]);

assert.throws(() => zlib.gunzipSync(data));

zlib.gunzip(data, common.mustCall((err, result) => {
  assert(err);
}));

// In this case the trailing junk is too short to be a gzip segment
// So we ignore it and decompression succeeds.
data = Buffer.concat([
  zlib.gzipSync('abc'),
  zlib.gzipSync('def'),
  Buffer([0x1f, 0x8b, 0xff, 0xff])
]);

assert.throws(() => zlib.gunzipSync(data));

zlib.gunzip(data, common.mustCall((err, result) => {
  assert(err);
}));

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js