mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
2b5acda7a2
Uses const where possible, removes inaccurate comments, prefers strictEqual where possible, ensures functions with assertions are called and enures the inflater has correct encoding set. PR-URL: https://github.com/nodejs/node/pull/8512 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
40 lines
931 B
JavaScript
40 lines
931 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const zlib = require('zlib');
|
|
|
|
// String "test" encoded with dictionary "dict".
|
|
const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]);
|
|
|
|
{
|
|
const stream = zlib.createInflate();
|
|
|
|
stream.on('error', common.mustCall(function(err) {
|
|
assert(/Missing dictionary/.test(err.message));
|
|
}));
|
|
|
|
stream.write(input);
|
|
}
|
|
|
|
{
|
|
const stream = zlib.createInflate({ dictionary: Buffer.from('fail') });
|
|
|
|
stream.on('error', common.mustCall(function(err) {
|
|
assert(/Bad dictionary/.test(err.message));
|
|
}));
|
|
|
|
stream.write(input);
|
|
}
|
|
|
|
{
|
|
const stream = zlib.createInflateRaw({ dictionary: Buffer.from('fail') });
|
|
|
|
stream.on('error', common.mustCall(function(err) {
|
|
// It's not possible to separate invalid dict and invalid data when using
|
|
// the raw format
|
|
assert(/invalid/.test(err.message));
|
|
}));
|
|
|
|
stream.write(input);
|
|
}
|