Skip to content

Commit

Permalink
Merge pull request #324 from dduponchel/v2.x
Browse files Browse the repository at this point in the history
Release v2.6.1
  • Loading branch information
dduponchel committed Jul 28, 2016
2 parents f494be6 + f65bd54 commit b06e8cd
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ layout: default
section: main
---

### v2.6.1 2016-07-28
- update pako to v1.0.2 to fix a DEFLATE bug (see [#322](https://github.com/Stuk/jszip/pull/322)).

### v2.6.0 2016-03-23
- publish `dist/` files in the npm package (see [#225](https://github.com/Stuk/jszip/pull/225)).
- update pako to v1.0.0 (see [#261](https://github.com/Stuk/jszip/pull/261)).
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jszip",
"repo": "Stuk/jszip",
"description": "Create, read and edit .zip files with Javascript http://stuartk.com/jszip",
"version": "2.6.0",
"version": "2.6.1",
"keywords": [
"zip",
"deflate",
Expand Down
179 changes: 172 additions & 7 deletions dist/jszip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2999,6 +2999,7 @@ var Z_DEFLATED = 8;
* - `windowBits`
* - `memLevel`
* - `strategy`
* - `dictionary`
*
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
* for more information on these.
Expand Down Expand Up @@ -3083,6 +3084,27 @@ function Deflate(options) {
if (opt.header) {
zlib_deflate.deflateSetHeader(this.strm, opt.header);
}

if (opt.dictionary) {
var dict;
// Convert data if needed
if (typeof opt.dictionary === 'string') {
// If we need to compress text, change encoding to utf8.
dict = strings.string2buf(opt.dictionary);
} else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
dict = new Uint8Array(opt.dictionary);
} else {
dict = opt.dictionary;
}

status = zlib_deflate.deflateSetDictionary(this.strm, dict);

if (status !== Z_OK) {
throw new Error(msg[status]);
}

this._dict_set = true;
}
}

/**
Expand Down Expand Up @@ -3229,6 +3251,7 @@ Deflate.prototype.onEnd = function (status) {
* - windowBits
* - memLevel
* - strategy
* - dictionary
*
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
* for more information on these.
Expand Down Expand Up @@ -3356,6 +3379,7 @@ var toString = Object.prototype.toString;
* on bad params. Supported options:
*
* - `windowBits`
* - `dictionary`
*
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
* for more information on these.
Expand Down Expand Up @@ -3475,8 +3499,10 @@ function Inflate(options) {
Inflate.prototype.push = function (data, mode) {
var strm = this.strm;
var chunkSize = this.options.chunkSize;
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 @@ -3507,6 +3533,20 @@ 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);

}

if (status === c.Z_BUF_ERROR && allowBufError === true) {
status = c.Z_OK;
allowBufError = false;
Expand Down Expand Up @@ -4305,6 +4345,7 @@ function read_buf(strm, buf, start, size) {

strm.avail_in -= len;

// zmemcpy(buf, strm->next_in, len);
utils.arraySet(buf, strm.input, strm.next_in, len, start);
if (strm.state.wrap === 1) {
strm.adler = adler32(strm.adler, buf, len, start);
Expand Down Expand Up @@ -5485,9 +5526,16 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */

s.pending_buf_size = s.lit_bufsize * 4;

//overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
//s->pending_buf = (uchf *) overlay;
s.pending_buf = new utils.Buf8(s.pending_buf_size);

s.d_buf = s.lit_bufsize >> 1;
// It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
//s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
s.d_buf = 1 * s.lit_bufsize;

//s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
s.l_buf = (1 + 2) * s.lit_bufsize;

s.level = level;
Expand Down Expand Up @@ -5860,12 +5908,94 @@ function deflateEnd(strm) {
return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
}


/* =========================================================================
* Copy the source state to the destination state
* Initializes the compression dictionary from the given byte
* sequence without producing any compressed output.
*/
//function deflateCopy(dest, source) {
//
//}
function deflateSetDictionary(strm, dictionary) {
var dictLength = dictionary.length;

var s;
var str, n;
var wrap;
var avail;
var next;
var input;
var tmpDict;

if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
return Z_STREAM_ERROR;
}

s = strm.state;
wrap = s.wrap;

if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) {
return Z_STREAM_ERROR;
}

/* when using zlib wrappers, compute Adler-32 for provided dictionary */
if (wrap === 1) {
/* adler32(strm->adler, dictionary, dictLength); */
strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
}

s.wrap = 0; /* avoid computing Adler-32 in read_buf */

/* if dictionary would fill window, just replace the history */
if (dictLength >= s.w_size) {
if (wrap === 0) { /* already empty otherwise */
/*** CLEAR_HASH(s); ***/
zero(s.head); // Fill with NIL (= 0);
s.strstart = 0;
s.block_start = 0;
s.insert = 0;
}
/* use the tail */
// dictionary = dictionary.slice(dictLength - s.w_size);
tmpDict = new utils.Buf8(s.w_size);
utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
dictionary = tmpDict;
dictLength = s.w_size;
}
/* insert dictionary into window and hash */
avail = strm.avail_in;
next = strm.next_in;
input = strm.input;
strm.avail_in = dictLength;
strm.next_in = 0;
strm.input = dictionary;
fill_window(s);
while (s.lookahead >= MIN_MATCH) {
str = s.strstart;
n = s.lookahead - (MIN_MATCH - 1);
do {
/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;

s.prev[str & s.w_mask] = s.head[s.ins_h];

s.head[s.ins_h] = str;
str++;
} while (--n);
s.strstart = str;
s.lookahead = MIN_MATCH - 1;
fill_window(s);
}
s.strstart += s.lookahead;
s.block_start = s.strstart;
s.insert = s.lookahead;
s.lookahead = 0;
s.match_length = s.prev_length = MIN_MATCH - 1;
s.match_available = 0;
strm.next_in = next;
strm.input = input;
strm.avail_in = avail;
s.wrap = wrap;
return Z_OK;
}


exports.deflateInit = deflateInit;
exports.deflateInit2 = deflateInit2;
Expand All @@ -5874,12 +6004,12 @@ exports.deflateResetKeep = deflateResetKeep;
exports.deflateSetHeader = deflateSetHeader;
exports.deflate = deflate;
exports.deflateEnd = deflateEnd;
exports.deflateSetDictionary = deflateSetDictionary;
exports.deflateInfo = 'pako deflate (from Nodeca project)';

/* Not implemented
exports.deflateBound = deflateBound;
exports.deflateCopy = deflateCopy;
exports.deflateSetDictionary = deflateSetDictionary;
exports.deflateParams = deflateParams;
exports.deflatePending = deflatePending;
exports.deflatePrime = deflatePrime;
Expand Down Expand Up @@ -7739,6 +7869,41 @@ function inflateGetHeader(strm, head) {
return Z_OK;
}

function inflateSetDictionary(strm, dictionary) {
var dictLength = dictionary.length;

var state;
var dictid;
var ret;

/* check state */
if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
state = strm.state;

if (state.wrap !== 0 && state.mode !== DICT) {
return Z_STREAM_ERROR;
}

/* check for correct dictionary identifier */
if (state.mode === DICT) {
dictid = 1; /* adler32(0, null, 0)*/
/* dictid = adler32(dictid, dictionary, dictLength); */
dictid = adler32(dictid, dictionary, dictLength, 0);
if (dictid !== state.check) {
return Z_DATA_ERROR;
}
}
/* copy dictionary to window using updatewindow(), which will amend the
existing dictionary if appropriate */
ret = updatewindow(strm, dictionary, dictLength, dictLength);
if (ret) {
state.mode = MEM;
return Z_MEM_ERROR;
}
state.havedict = 1;
// Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
}

exports.inflateReset = inflateReset;
exports.inflateReset2 = inflateReset2;
Expand All @@ -7748,14 +7913,14 @@ exports.inflateInit2 = inflateInit2;
exports.inflate = inflate;
exports.inflateEnd = inflateEnd;
exports.inflateGetHeader = inflateGetHeader;
exports.inflateSetDictionary = inflateSetDictionary;
exports.inflateInfo = 'pako inflate (from Nodeca project)';

/* Not implemented
exports.inflateCopy = inflateCopy;
exports.inflateGetDictionary = inflateGetDictionary;
exports.inflateMark = inflateMark;
exports.inflatePrime = inflatePrime;
exports.inflateSetDictionary = inflateSetDictionary;
exports.inflateSync = inflateSync;
exports.inflateSyncPoint = inflateSyncPoint;
exports.inflateUndermine = inflateUndermine;
Expand Down
6 changes: 3 additions & 3 deletions dist/jszip.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
<div class="col-md-7">
<p>
<strong>Current version</strong> : v2.6.0
<strong>Current version</strong> : v2.6.1
</p>
<p>
<strong>License</strong> : JSZip is dual-licensed. You may use it under the
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jszip",
"version": "2.6.0",
"version": "2.6.1",
"author": "Stuart Knightley <stuart@stuartk.com>",
"description": "Create, read and edit .zip files with Javascript http://stuartk.com/jszip",
"scripts": {
Expand Down

0 comments on commit b06e8cd

Please sign in to comment.