mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

Changes in test-zlib-from-string is because var->const pushed us over the max char limit per line. PR-URL: https://github.com/nodejs/node/pull/8627 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const zlib = require('zlib');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'));
|
|
const chunkSize = 12 * 1024;
|
|
const opts = { level: 9, strategy: zlib.constants.Z_DEFAULT_STRATEGY };
|
|
const deflater = zlib.createDeflate(opts);
|
|
|
|
const chunk1 = file.slice(0, chunkSize);
|
|
const chunk2 = file.slice(chunkSize);
|
|
const blkhdr = Buffer.from([0x00, 0x5a, 0x82, 0xa5, 0x7d]);
|
|
const expected = Buffer.concat([blkhdr, chunk2]);
|
|
let actual;
|
|
|
|
deflater.write(chunk1, function() {
|
|
deflater.params(0, zlib.constants.Z_DEFAULT_STRATEGY, function() {
|
|
while (deflater.read());
|
|
deflater.end(chunk2, function() {
|
|
const bufs = [];
|
|
var buf;
|
|
while (buf = deflater.read())
|
|
bufs.push(buf);
|
|
actual = Buffer.concat(bufs);
|
|
});
|
|
});
|
|
while (deflater.read());
|
|
});
|
|
|
|
process.once('exit', function() {
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|