0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-zlib-params.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

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 = [];
let buf;
while (buf = deflater.read())
bufs.push(buf);
actual = Buffer.concat(bufs);
});
});
while (deflater.read());
});
process.once('exit', function() {
assert.deepStrictEqual(actual, expected);
});