From 147d47409e223ba152a6329d4d48bd146e63bda8 Mon Sep 17 00:00:00 2001 From: 101arrowz Date: Mon, 1 Mar 2021 03:11:29 -0800 Subject: [PATCH 1/2] Fix unzip error in post-termination extraction --- README.md | 3 +++ package.json | 2 +- src/index.ts | 4 ++-- test/util.ts | 3 +-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5082e75..9d373a1 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,9 @@ unzipper.onfile = file => { } }; +// Try to keep under 5,000 files per chunk to avoid stack limit errors +// For example, if all files are a few kB, multi-megabyte chunks are OK +// If files are mostly under 100 bytes, 64kB chunks are the limit unzipper.push(zipChunk1); unzipper.push(zipChunk2); unzipper.push(zipChunk3, true); diff --git a/package.json b/package.json index 39696b1..6c87254 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fflate", - "version": "0.6.5", + "version": "0.6.6", "description": "High performance (de)compression in an 8kB package", "main": "./lib/index.cjs", "module": "./esm/browser.js", diff --git a/src/index.ts b/src/index.ts index c615b4f..e02d762 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3004,7 +3004,7 @@ export class Unzip { */ push(chunk: Uint8Array, final?: boolean) { if (!this.onfile) throw 'no callback'; - if (!this.k) throw 'stream finished'; + if (!this.p) throw 'stream finished'; if (this.c > 0) { const len = Math.min(this.c, chunk.length); const toAdd = chunk.subarray(0, len); @@ -3084,7 +3084,7 @@ export class Unzip { } if (final) { if (this.c) throw 'invalid zip file'; - this.k = null; + this.p = null; } } diff --git a/test/util.ts b/test/util.ts index 50abad3..e91201f 100644 --- a/test/util.ts +++ b/test/util.ts @@ -15,8 +15,7 @@ const testFiles = { const testZipFiles = { model3D: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/kmz/Box.kmz', - largeModel3D: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/3mf/truck.3mf', - repo: 'https://codeload.github.com/parcel-bundler/parcel/zip/v2' + largeModel3D: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/3mf/truck.3mf' }; const dlCached = async >(files: T) => { From 774b6688918a4fed5064522e4da22b9f075869ea Mon Sep 17 00:00:00 2001 From: 101arrowz Date: Mon, 1 Mar 2021 04:00:26 -0800 Subject: [PATCH 2/2] Fix last file in streaming unzip never having final set --- package.json | 2 +- src/index.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6c87254..2d62f54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fflate", - "version": "0.6.6", + "version": "0.6.7", "description": "High performance (de)compression in an 8kB package", "main": "./lib/index.cjs", "module": "./esm/browser.js", diff --git a/src/index.ts b/src/index.ts index e02d762..443a3c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3039,6 +3039,7 @@ export class Unzip { else if (dd) sc = -1; i += es; this.c = sc; + let d: UnzipDecoder; const file = { name: fn, compression: cmp, @@ -3048,15 +3049,15 @@ export class Unzip { else { const ctr = this.o[cmp]; if (!ctr) throw 'unknown compression type ' + cmp; - const d = sc < 0 ? new ctr(fn) : new ctr(fn, sc, su); + d = sc < 0 ? new ctr(fn) : new ctr(fn, sc, su); d.ondata = (err, dat, final) => { file.ondata(err, dat, final); } for (const dat of chks) d.push(dat, false); - if (this.k[0] == chks) this.d = d; + if (this.k[0] == chks && this.c) this.d = d; else d.push(et, true); } }, terminate: () => { - if (this.k[0] == chks && this.d.terminate) this.d.terminate(); + if (d && d.terminate) d.terminate(); } } as UnzipFile; if (sc >= 0) file.size = sc, file.originalSize = su;