Skip to content

Commit

Permalink
Merge pull request #482 from dduponchel/release_3.1.5
Browse files Browse the repository at this point in the history
Release 3.1.5
  • Loading branch information
dduponchel committed Nov 9, 2017
2 parents ece381a + a4138a2 commit 9fb481a
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 64 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,14 @@ layout: default
section: main
---

### v3.1.5 2017-11-09
- Fix IE11 memory leak (see [#429](https://github.com/Stuk/jszip/pull/429)).
- Handle 2 nodejs deprecations (see [#459](https://github.com/Stuk/jszip/pull/459)).
- Improve the "unsupported format" error message (see [#461](https://github.com/Stuk/jszip/pull/461)).
- Improve webworker compatibility (see [#468](https://github.com/Stuk/jszip/pull/468)).
- Fix nodejs 0.10 compatibility (see [#480](https://github.com/Stuk/jszip/pull/480)).
- Improve the error without type in async() (see [#481](https://github.com/Stuk/jszip/pull/481)).

### v3.1.4 2017-08-24
- consistently use our own utils object for inheritance (see [#395](https://github.com/Stuk/jszip/pull/395)).
- lower the memory consumption in `generate*` with a lot of files (see [#449](https://github.com/Stuk/jszip/pull/449)).
Expand Down
2 changes: 1 addition & 1 deletion component.json
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": "3.1.4",
"version": "3.1.5",
"keywords": [
"zip",
"deflate",
Expand Down
126 changes: 72 additions & 54 deletions dist/jszip.js
@@ -1,6 +1,6 @@
/*!
JSZip v3.1.3 - A Javascript class for generating and reading zip files
JSZip v3.1.5 - A JavaScript class for generating and reading zip files
<http://stuartk.com/jszip>
(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
Expand Down Expand Up @@ -1057,7 +1057,7 @@ JSZip.defaults = require('./defaults');

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

JSZip.loadAsync = function (content, options) {
return new JSZip().loadAsync(content, options);
Expand Down Expand Up @@ -1281,14 +1281,32 @@ module.exports = {
*/
isNode : typeof Buffer !== "undefined",
/**
* Create a new nodejs Buffer.
* Create a new nodejs Buffer from an existing content.
* @param {Object} data the data to pass to the constructor.
* @param {String} encoding the encoding to use.
* @return {Buffer} a new Buffer.
*/
newBuffer : function(data, encoding){
newBufferFrom: function(data, encoding) {
// XXX We can't use `Buffer.from` which comes from `Uint8Array.from`
// in nodejs v4 (< v.4.5). It's not the expected implementation (and
// has a different signature).
// see https://github.com/nodejs/node/issues/8053
// A condition on nodejs' version won't solve the issue as we don't
// control the Buffer polyfills that may or may not be used.
return new Buffer(data, encoding);
},
/**
* Create a new nodejs Buffer with the specified size.
* @param {Integer} size the size of the buffer.
* @return {Buffer} a new Buffer.
*/
allocBuffer: function (size) {
if (Buffer.alloc) {
return Buffer.alloc(size);
} else {
return new Buffer(size);
}
},
/**
* Find out if an object is a Buffer.
* @param {Object} b the object to test.
Expand Down Expand Up @@ -1787,7 +1805,7 @@ DataReader.prototype = {
this.checkIndex(this.index + offset);
},
/**
* Check that the specifed index will not be too far.
* Check that the specified index will not be too far.
* @param {string} newIndex the index to check.
* @throws {Error} an Error if the index is out of bounds.
*/
Expand Down Expand Up @@ -2498,24 +2516,19 @@ if (support.nodestream) {
* Apply the final transformation of the data. If the user wants a Blob for
* example, it's easier to work with an U8intArray and finally do the
* ArrayBuffer/Blob conversion.
* @param {String} resultType the name of the final type
* @param {String} chunkType the type of the data in the given array.
* @param {Array} dataArray the array containing the data chunks to concatenate
* @param {String} type the name of the final type
* @param {String|Uint8Array|Buffer} content the content to transform
* @param {String} mimeType the mime type of the content, if applicable.
* @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the content in the right format.
*/
function transformZipOutput(resultType, chunkType, dataArray, mimeType) {
var content = null;
switch(resultType) {
function transformZipOutput(type, content, mimeType) {
switch(type) {
case "blob" :
return utils.newBlob(dataArray, mimeType);
return utils.newBlob(utils.transformTo("arraybuffer", content), mimeType);
case "base64" :
content = concat(chunkType, dataArray);
return base64.encode(content);
default :
content = concat(chunkType, dataArray);
return utils.transformTo(resultType, content);
return utils.transformTo(type, content);
}
}

Expand Down Expand Up @@ -2578,7 +2591,7 @@ function accumulate(helper, updateCallback) {
})
.on('end', function (){
try {
var result = transformZipOutput(resultType, chunkType, dataArray, mimeType);
var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
resolve(result);
} catch (e) {
reject(e);
Expand All @@ -2600,8 +2613,6 @@ function StreamHelper(worker, outputType, mimeType) {
var internalType = outputType;
switch(outputType) {
case "blob":
internalType = "arraybuffer";
break;
case "arraybuffer":
internalType = "uint8array";
break;
Expand Down Expand Up @@ -2721,7 +2732,7 @@ else {
}
catch (e) {
try {
var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
var builder = new Builder();
builder.append(buffer);
exports.blob = builder.getBlob('application/zip').size === 0;
Expand Down Expand Up @@ -2909,7 +2920,7 @@ var buf2string = function (buf) {
*/
exports.utf8encode = function utf8encode(str) {
if (support.nodebuffer) {
return nodejsUtils.newBuffer(str, "utf-8");
return nodejsUtils.newBufferFrom(str, "utf-8");
}

return string2buf(str);
Expand Down Expand Up @@ -3044,30 +3055,33 @@ function string2binary(str) {

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

try {
// Blob constructor
return new Blob(parts, {
return new Blob([part], {
type: type
});
}
catch (e) {

try {
// deprecated, browser only, old way
var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
var builder = new Builder();
for (var i = 0; i < parts.length; i++) {
builder.append(parts[i]);
}
builder.append(part);
return builder.getBlob(type);
}
catch (e) {
Expand Down Expand Up @@ -3163,7 +3177,7 @@ var arrayToStringHelper = {
*/
nodebuffer : (function () {
try {
return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.newBuffer(1)).length === 1;
return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.allocBuffer(1)).length === 1;
} catch (e) {
return false;
}
Expand Down Expand Up @@ -3243,7 +3257,7 @@ transform["string"] = {
return stringToArrayLike(input, new Uint8Array(input.length));
},
"nodebuffer": function(input) {
return stringToArrayLike(input, nodejsUtils.newBuffer(input.length));
return stringToArrayLike(input, nodejsUtils.allocBuffer(input.length));
}
};

Expand All @@ -3258,7 +3272,7 @@ transform["array"] = {
return new Uint8Array(input);
},
"nodebuffer": function(input) {
return nodejsUtils.newBuffer(input);
return nodejsUtils.newBufferFrom(input);
}
};

Expand All @@ -3275,7 +3289,7 @@ transform["arraybuffer"] = {
return new Uint8Array(input);
},
"nodebuffer": function(input) {
return nodejsUtils.newBuffer(new Uint8Array(input));
return nodejsUtils.newBufferFrom(new Uint8Array(input));
}
};

Expand All @@ -3286,17 +3300,11 @@ transform["uint8array"] = {
return arrayLikeToArrayLike(input, new Array(input.length));
},
"arraybuffer": function(input) {
// copy the uint8array: DO NOT propagate the original ArrayBuffer, it
// can be way larger (the whole zip file for example).
var copy = new Uint8Array(input.length);
if (input.length) {
copy.set(input, 0);
}
return copy.buffer;
return input.buffer;
},
"uint8array": identity,
"nodebuffer": function(input) {
return nodejsUtils.newBuffer(input);
return nodejsUtils.newBufferFrom(input);
}
};

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

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

/*
Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from
the zip file can fit into a 32bits integer. This cannot be solved : Javascript represents
the zip file can fit into a 32bits integer. This cannot be solved : JavaScript represents
all numbers as 64-bit double precision IEEE 754 floating point numbers.
So, we have 53bits for integers and bitwise operations treat everything as 32bits.
see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators
Expand Down Expand Up @@ -4093,20 +4102,29 @@ ZipObject.prototype = {
* @return StreamHelper the stream.
*/
internalStream: function (type) {
var outputType = type.toLowerCase();
var askUnicodeString = outputType === "string" || outputType === "text";
if (outputType === "binarystring" || outputType === "text") {
outputType = "string";
}
var result = this._decompressWorker();
var result = null, outputType = "string";
try {
if (!type) {
throw new Error("No output type specified.");
}
outputType = type.toLowerCase();
var askUnicodeString = outputType === "string" || outputType === "text";
if (outputType === "binarystring" || outputType === "text") {
outputType = "string";
}
result = this._decompressWorker();

var isUnicodeString = !this._dataBinary;
var isUnicodeString = !this._dataBinary;

if (isUnicodeString && !askUnicodeString) {
result = result.pipe(new utf8.Utf8EncodeWorker());
}
if (!isUnicodeString && askUnicodeString) {
result = result.pipe(new utf8.Utf8DecodeWorker());
if (isUnicodeString && !askUnicodeString) {
result = result.pipe(new utf8.Utf8EncodeWorker());
}
if (!isUnicodeString && askUnicodeString) {
result = result.pipe(new utf8.Utf8DecodeWorker());
}
} catch (e) {
result = new GenericWorker("error");
result.error(e);
}

return new StreamHelper(result, outputType, "");
Expand Down
10 changes: 5 additions & 5 deletions dist/jszip.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -13,7 +13,7 @@
</div>
<div class="col-md-7">
<p>
<strong>Current version</strong> : v3.1.4
<strong>Current version</strong> : v3.1.5
</p>
<p>
<strong>License</strong> : JSZip is dual-licensed. You may use it under the
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -42,7 +42,7 @@ JSZip.defaults = require('./defaults');

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

JSZip.loadAsync = function (content, options) {
return new JSZip().loadAsync(content, options);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jszip",
"version": "3.1.4",
"version": "3.1.5",
"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 9fb481a

Please sign in to comment.