Skip to content

Commit 9fb481a

Browse files
authored
Merge pull request #482 from dduponchel/release_3.1.5
Release 3.1.5
2 parents ece381a + a4138a2 commit 9fb481a

File tree

8 files changed

+90
-64
lines changed

8 files changed

+90
-64
lines changed

CHANGES.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ layout: default
44
section: main
55
---
66

7+
### v3.1.5 2017-11-09
8+
- Fix IE11 memory leak (see [#429](https://github.com/Stuk/jszip/pull/429)).
9+
- Handle 2 nodejs deprecations (see [#459](https://github.com/Stuk/jszip/pull/459)).
10+
- Improve the "unsupported format" error message (see [#461](https://github.com/Stuk/jszip/pull/461)).
11+
- Improve webworker compatibility (see [#468](https://github.com/Stuk/jszip/pull/468)).
12+
- Fix nodejs 0.10 compatibility (see [#480](https://github.com/Stuk/jszip/pull/480)).
13+
- Improve the error without type in async() (see [#481](https://github.com/Stuk/jszip/pull/481)).
14+
715
### v3.1.4 2017-08-24
816
- consistently use our own utils object for inheritance (see [#395](https://github.com/Stuk/jszip/pull/395)).
917
- lower the memory consumption in `generate*` with a lot of files (see [#449](https://github.com/Stuk/jszip/pull/449)).

component.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jszip",
33
"repo": "Stuk/jszip",
44
"description": "Create, read and edit .zip files with JavaScript http://stuartk.com/jszip",
5-
"version": "3.1.4",
5+
"version": "3.1.5",
66
"keywords": [
77
"zip",
88
"deflate",

dist/jszip.js

+72-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
JSZip v3.1.3 - A Javascript class for generating and reading zip files
3+
JSZip v3.1.5 - A JavaScript class for generating and reading zip files
44
<http://stuartk.com/jszip>
55
66
(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
@@ -1057,7 +1057,7 @@ JSZip.defaults = require('./defaults');
10571057

10581058
// TODO find a better way to handle this version,
10591059
// a require('package.json').version doesn't work with webpack, see #327
1060-
JSZip.version = "3.1.3";
1060+
JSZip.version = "3.1.5";
10611061

10621062
JSZip.loadAsync = function (content, options) {
10631063
return new JSZip().loadAsync(content, options);
@@ -1281,14 +1281,32 @@ module.exports = {
12811281
*/
12821282
isNode : typeof Buffer !== "undefined",
12831283
/**
1284-
* Create a new nodejs Buffer.
1284+
* Create a new nodejs Buffer from an existing content.
12851285
* @param {Object} data the data to pass to the constructor.
12861286
* @param {String} encoding the encoding to use.
12871287
* @return {Buffer} a new Buffer.
12881288
*/
1289-
newBuffer : function(data, encoding){
1289+
newBufferFrom: function(data, encoding) {
1290+
// XXX We can't use `Buffer.from` which comes from `Uint8Array.from`
1291+
// in nodejs v4 (< v.4.5). It's not the expected implementation (and
1292+
// has a different signature).
1293+
// see https://github.com/nodejs/node/issues/8053
1294+
// A condition on nodejs' version won't solve the issue as we don't
1295+
// control the Buffer polyfills that may or may not be used.
12901296
return new Buffer(data, encoding);
12911297
},
1298+
/**
1299+
* Create a new nodejs Buffer with the specified size.
1300+
* @param {Integer} size the size of the buffer.
1301+
* @return {Buffer} a new Buffer.
1302+
*/
1303+
allocBuffer: function (size) {
1304+
if (Buffer.alloc) {
1305+
return Buffer.alloc(size);
1306+
} else {
1307+
return new Buffer(size);
1308+
}
1309+
},
12921310
/**
12931311
* Find out if an object is a Buffer.
12941312
* @param {Object} b the object to test.
@@ -1787,7 +1805,7 @@ DataReader.prototype = {
17871805
this.checkIndex(this.index + offset);
17881806
},
17891807
/**
1790-
* Check that the specifed index will not be too far.
1808+
* Check that the specified index will not be too far.
17911809
* @param {string} newIndex the index to check.
17921810
* @throws {Error} an Error if the index is out of bounds.
17931811
*/
@@ -2498,24 +2516,19 @@ if (support.nodestream) {
24982516
* Apply the final transformation of the data. If the user wants a Blob for
24992517
* example, it's easier to work with an U8intArray and finally do the
25002518
* ArrayBuffer/Blob conversion.
2501-
* @param {String} resultType the name of the final type
2502-
* @param {String} chunkType the type of the data in the given array.
2503-
* @param {Array} dataArray the array containing the data chunks to concatenate
2519+
* @param {String} type the name of the final type
25042520
* @param {String|Uint8Array|Buffer} content the content to transform
25052521
* @param {String} mimeType the mime type of the content, if applicable.
25062522
* @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the content in the right format.
25072523
*/
2508-
function transformZipOutput(resultType, chunkType, dataArray, mimeType) {
2509-
var content = null;
2510-
switch(resultType) {
2524+
function transformZipOutput(type, content, mimeType) {
2525+
switch(type) {
25112526
case "blob" :
2512-
return utils.newBlob(dataArray, mimeType);
2527+
return utils.newBlob(utils.transformTo("arraybuffer", content), mimeType);
25132528
case "base64" :
2514-
content = concat(chunkType, dataArray);
25152529
return base64.encode(content);
25162530
default :
2517-
content = concat(chunkType, dataArray);
2518-
return utils.transformTo(resultType, content);
2531+
return utils.transformTo(type, content);
25192532
}
25202533
}
25212534

@@ -2578,7 +2591,7 @@ function accumulate(helper, updateCallback) {
25782591
})
25792592
.on('end', function (){
25802593
try {
2581-
var result = transformZipOutput(resultType, chunkType, dataArray, mimeType);
2594+
var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
25822595
resolve(result);
25832596
} catch (e) {
25842597
reject(e);
@@ -2600,8 +2613,6 @@ function StreamHelper(worker, outputType, mimeType) {
26002613
var internalType = outputType;
26012614
switch(outputType) {
26022615
case "blob":
2603-
internalType = "arraybuffer";
2604-
break;
26052616
case "arraybuffer":
26062617
internalType = "uint8array";
26072618
break;
@@ -2721,7 +2732,7 @@ else {
27212732
}
27222733
catch (e) {
27232734
try {
2724-
var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
2735+
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
27252736
var builder = new Builder();
27262737
builder.append(buffer);
27272738
exports.blob = builder.getBlob('application/zip').size === 0;
@@ -2909,7 +2920,7 @@ var buf2string = function (buf) {
29092920
*/
29102921
exports.utf8encode = function utf8encode(str) {
29112922
if (support.nodebuffer) {
2912-
return nodejsUtils.newBuffer(str, "utf-8");
2923+
return nodejsUtils.newBufferFrom(str, "utf-8");
29132924
}
29142925

29152926
return string2buf(str);
@@ -3044,30 +3055,33 @@ function string2binary(str) {
30443055

30453056
/**
30463057
* Create a new blob with the given content and the given type.
3047-
* @param {Array[String|ArrayBuffer]} parts the content to put in the blob. DO NOT use
3058+
* @param {String|ArrayBuffer} part the content to put in the blob. DO NOT use
30483059
* an Uint8Array because the stock browser of android 4 won't accept it (it
30493060
* will be silently converted to a string, "[object Uint8Array]").
3061+
*
3062+
* Use only ONE part to build the blob to avoid a memory leak in IE11 / Edge:
3063+
* when a large amount of Array is used to create the Blob, the amount of
3064+
* memory consumed is nearly 100 times the original data amount.
3065+
*
30503066
* @param {String} type the mime type of the blob.
30513067
* @return {Blob} the created blob.
30523068
*/
3053-
exports.newBlob = function(parts, type) {
3069+
exports.newBlob = function(part, type) {
30543070
exports.checkSupport("blob");
30553071

30563072
try {
30573073
// Blob constructor
3058-
return new Blob(parts, {
3074+
return new Blob([part], {
30593075
type: type
30603076
});
30613077
}
30623078
catch (e) {
30633079

30643080
try {
30653081
// deprecated, browser only, old way
3066-
var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
3082+
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
30673083
var builder = new Builder();
3068-
for (var i = 0; i < parts.length; i++) {
3069-
builder.append(parts[i]);
3070-
}
3084+
builder.append(part);
30713085
return builder.getBlob(type);
30723086
}
30733087
catch (e) {
@@ -3163,7 +3177,7 @@ var arrayToStringHelper = {
31633177
*/
31643178
nodebuffer : (function () {
31653179
try {
3166-
return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.newBuffer(1)).length === 1;
3180+
return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.allocBuffer(1)).length === 1;
31673181
} catch (e) {
31683182
return false;
31693183
}
@@ -3243,7 +3257,7 @@ transform["string"] = {
32433257
return stringToArrayLike(input, new Uint8Array(input.length));
32443258
},
32453259
"nodebuffer": function(input) {
3246-
return stringToArrayLike(input, nodejsUtils.newBuffer(input.length));
3260+
return stringToArrayLike(input, nodejsUtils.allocBuffer(input.length));
32473261
}
32483262
};
32493263

@@ -3258,7 +3272,7 @@ transform["array"] = {
32583272
return new Uint8Array(input);
32593273
},
32603274
"nodebuffer": function(input) {
3261-
return nodejsUtils.newBuffer(input);
3275+
return nodejsUtils.newBufferFrom(input);
32623276
}
32633277
};
32643278

@@ -3275,7 +3289,7 @@ transform["arraybuffer"] = {
32753289
return new Uint8Array(input);
32763290
},
32773291
"nodebuffer": function(input) {
3278-
return nodejsUtils.newBuffer(new Uint8Array(input));
3292+
return nodejsUtils.newBufferFrom(new Uint8Array(input));
32793293
}
32803294
};
32813295

@@ -3286,17 +3300,11 @@ transform["uint8array"] = {
32863300
return arrayLikeToArrayLike(input, new Array(input.length));
32873301
},
32883302
"arraybuffer": function(input) {
3289-
// copy the uint8array: DO NOT propagate the original ArrayBuffer, it
3290-
// can be way larger (the whole zip file for example).
3291-
var copy = new Uint8Array(input.length);
3292-
if (input.length) {
3293-
copy.set(input, 0);
3294-
}
3295-
return copy.buffer;
3303+
return input.buffer;
32963304
},
32973305
"uint8array": identity,
32983306
"nodebuffer": function(input) {
3299-
return nodejsUtils.newBuffer(input);
3307+
return nodejsUtils.newBufferFrom(input);
33003308
}
33013309
};
33023310

@@ -3472,7 +3480,8 @@ exports.prepareContent = function(name, inputData, isBinary, isOptimizedBinarySt
34723480

34733481
if (!dataType) {
34743482
return external.Promise.reject(
3475-
new Error("The data of '" + name + "' is in an unsupported format !")
3483+
new Error("Can't read the data of '" + name + "'. Is it " +
3484+
"in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?")
34763485
);
34773486
}
34783487
// special case : it's way easier to work with Uint8Array than with ArrayBuffer
@@ -3515,7 +3524,7 @@ function ZipEntries(loadOptions) {
35153524
}
35163525
ZipEntries.prototype = {
35173526
/**
3518-
* Check that the reader is on the speficied signature.
3527+
* Check that the reader is on the specified signature.
35193528
* @param {string} expectedSignature the expected signature.
35203529
* @throws {Error} if it is an other signature.
35213530
*/
@@ -3691,7 +3700,7 @@ ZipEntries.prototype = {
36913700

36923701
/*
36933702
Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from
3694-
the zip file can fit into a 32bits integer. This cannot be solved : Javascript represents
3703+
the zip file can fit into a 32bits integer. This cannot be solved : JavaScript represents
36953704
all numbers as 64-bit double precision IEEE 754 floating point numbers.
36963705
So, we have 53bits for integers and bitwise operations treat everything as 32bits.
36973706
see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators
@@ -4093,20 +4102,29 @@ ZipObject.prototype = {
40934102
* @return StreamHelper the stream.
40944103
*/
40954104
internalStream: function (type) {
4096-
var outputType = type.toLowerCase();
4097-
var askUnicodeString = outputType === "string" || outputType === "text";
4098-
if (outputType === "binarystring" || outputType === "text") {
4099-
outputType = "string";
4100-
}
4101-
var result = this._decompressWorker();
4105+
var result = null, outputType = "string";
4106+
try {
4107+
if (!type) {
4108+
throw new Error("No output type specified.");
4109+
}
4110+
outputType = type.toLowerCase();
4111+
var askUnicodeString = outputType === "string" || outputType === "text";
4112+
if (outputType === "binarystring" || outputType === "text") {
4113+
outputType = "string";
4114+
}
4115+
result = this._decompressWorker();
41024116

4103-
var isUnicodeString = !this._dataBinary;
4117+
var isUnicodeString = !this._dataBinary;
41044118

4105-
if (isUnicodeString && !askUnicodeString) {
4106-
result = result.pipe(new utf8.Utf8EncodeWorker());
4107-
}
4108-
if (!isUnicodeString && askUnicodeString) {
4109-
result = result.pipe(new utf8.Utf8DecodeWorker());
4119+
if (isUnicodeString && !askUnicodeString) {
4120+
result = result.pipe(new utf8.Utf8EncodeWorker());
4121+
}
4122+
if (!isUnicodeString && askUnicodeString) {
4123+
result = result.pipe(new utf8.Utf8DecodeWorker());
4124+
}
4125+
} catch (e) {
4126+
result = new GenericWorker("error");
4127+
result.error(e);
41104128
}
41114129

41124130
return new StreamHelper(result, outputType, "");

dist/jszip.min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
<div class="col-md-7">
1515
<p>
16-
<strong>Current version</strong> : v3.1.4
16+
<strong>Current version</strong> : v3.1.5
1717
</p>
1818
<p>
1919
<strong>License</strong> : JSZip is dual-licensed. You may use it under the

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ JSZip.defaults = require('./defaults');
4242

4343
// TODO find a better way to handle this version,
4444
// a require('package.json').version doesn't work with webpack, see #327
45-
JSZip.version = "3.1.4";
45+
JSZip.version = "3.1.5";
4646

4747
JSZip.loadAsync = function (content, options) {
4848
return new JSZip().loadAsync(content, options);

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jszip",
3-
"version": "3.1.4",
3+
"version": "3.1.5",
44
"author": "Stuart Knightley <[email protected]>",
55
"description": "Create, read and edit .zip files with JavaScript http://stuartk.com/jszip",
66
"scripts": {

0 commit comments

Comments
 (0)