Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions lib/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ function Inflate(options) {
this.header = new GZheader();

zlib_inflate.inflateGetHeader(this.strm, this.header);

// Setup dictionary
if (opt.dictionary) {
// Convert data if needed
if (typeof opt.dictionary === 'string') {
opt.dictionary = strings.string2buf(opt.dictionary);
} else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
opt.dictionary = new Uint8Array(opt.dictionary);
}
if (opt.raw) zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary); //In raw mode we need to set the dictionary early
}
}

/**
Expand Down Expand Up @@ -180,7 +191,6 @@ Inflate.prototype.push = function (data, mode) {
var dictionary = this.options.dictionary;
var status, _mode;
var next_out_utf8, tail, utf8str;
var dict;

// Flag to properly process Z_BUF_ERROR on testing inflate call
// when we check that all output data was flushed.
Expand Down Expand Up @@ -212,17 +222,7 @@ Inflate.prototype.push = function (data, mode) {
status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */

if (status === c.Z_NEED_DICT && dictionary) {
// Convert data if needed
if (typeof dictionary === 'string') {
dict = strings.string2buf(dictionary);
} else if (toString.call(dictionary) === '[object ArrayBuffer]') {
dict = new Uint8Array(dictionary);
} else {
dict = dictionary;
}

status = zlib_inflate.inflateSetDictionary(this.strm, dict);

status = zlib_inflate.inflateSetDictionary(this.strm, dictionary);
}

if (status === c.Z_BUF_ERROR && allowBufError === true) {
Expand Down
12 changes: 11 additions & 1 deletion test/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,18 @@ describe('Inflate with dictionary', function () {

it('spdy dictionary', function () {
var spdyDict = require('fs').readFileSync(require('path').join(__dirname, 'fixtures', 'spdy_dict.txt'));
testInflate(samples, { dictionary: spdyDict }, { dictionary: spdyDict });
});

testInflate(samples, { dictionary: spdyDict }, { dictionary: helpers.spdyDict });
it('should throw if directory is not supplied to raw inflate', function () {
var dict = new Buffer('abcdefghijklmnoprstuvwxyz');
assert.throws(function () {
testInflate(samples, { raw: true }, { raw: true, dictionary: dict });
});
});

it('tests raw inflate with spdy dictionary', function () {
var spdyDict = require('fs').readFileSync(require('path').join(__dirname, 'fixtures', 'spdy_dict.txt'));
testInflate(samples, { raw: true, dictionary: spdyDict }, { raw: true, dictionary: spdyDict });
});
});