diff --git a/CHANGELOG.md b/CHANGELOG.md index eba4b7a..8bf13ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## 0.7.0 +## 0.6.3 +- Patch exports of async functions +- Fix streaming unzip +## 0.6.2 - Replace Adler-32 implementation (used in Zlib compression) with one more optimized for V8 - Advice from @SheetJSDev - Add support for extra fields, file comments in ZIP files diff --git a/docs/classes/asyncunzipinflate.md b/docs/classes/asyncunzipinflate.md index 7d0cfd9..befe5f1 100644 --- a/docs/classes/asyncunzipinflate.md +++ b/docs/classes/asyncunzipinflate.md @@ -30,7 +30,7 @@ Asynchronous streaming DEFLATE decompression for ZIP archives ### constructor -\+ **new AsyncUnzipInflate**(`_`: string, `sz`: number): [AsyncUnzipInflate](asyncunzipinflate.md) +\+ **new AsyncUnzipInflate**(`_`: string, `sz?`: number): [AsyncUnzipInflate](asyncunzipinflate.md) Creates a DEFLATE decompression that can be used in ZIP archives @@ -39,7 +39,7 @@ Creates a DEFLATE decompression that can be used in ZIP archives Name | Type | ------ | ------ | `_` | string | -`sz` | number | +`sz?` | number | **Returns:** [AsyncUnzipInflate](asyncunzipinflate.md) diff --git a/docs/classes/unzip.md b/docs/classes/unzip.md index e081410..d0f8292 100644 --- a/docs/classes/unzip.md +++ b/docs/classes/unzip.md @@ -49,7 +49,7 @@ The handler to call whenever a file is discovered ### push -▸ **push**(`chunk`: Uint8Array, `final`: boolean): any +▸ **push**(`chunk`: Uint8Array, `final?`: boolean): any Pushes a chunk to be unzipped @@ -58,7 +58,7 @@ Pushes a chunk to be unzipped Name | Type | Description | ------ | ------ | ------ | `chunk` | Uint8Array | The chunk to push | -`final` | boolean | Whether this is the last chunk | +`final?` | boolean | Whether this is the last chunk | **Returns:** any diff --git a/package.json b/package.json index e0693b7..fc98e39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fflate", - "version": "0.6.2", + "version": "0.6.3", "description": "High performance (de)compression in an 8kB package", "main": "./lib/index.cjs", "module": "./esm/browser.js", diff --git a/scripts/rewriteBuilds.ts b/scripts/rewriteBuilds.ts index 65b1ecf..9d19d13 100644 --- a/scripts/rewriteBuilds.ts +++ b/scripts/rewriteBuilds.ts @@ -1,28 +1,39 @@ import { readFileSync, writeFileSync, unlinkSync, renameSync } from 'fs'; import { join } from 'path'; const atClass = /\/\*\* \@class \*\//g, pure = '/*#__PURE__*/'; -const extraneousExports = /exports\.(.*) = void 0;\n/; +const esModule = /exports.__esModule = true;\n/; const libDir = join(__dirname, '..', 'lib'); const libIndex = join(libDir, 'index.js'); -const lib = readFileSync(libIndex, 'utf-8').replace(atClass, pure).replace(extraneousExports, ''); +const lib = readFileSync(libIndex, 'utf-8') + .replace(atClass, pure) + .replace(esModule, '') + .replace(/exports\.(.*) = void 0;\n/, ''); writeFileSync(libIndex, lib); const esmDir = join(__dirname, '..', 'esm'); const esmIndex = join(esmDir, 'index.js'), esmWK = join(esmDir, 'worker.js'), - esmNWK = join(esmDir, 'node-worker.js'); + esmNWK = join(esmDir, 'node-worker.js'), + libWK = join(libDir, 'worker.js'), + libNWK = join(libDir, 'node-worker.js'); const esm = readFileSync(esmIndex, 'utf-8').replace(atClass, pure); const wk = readFileSync(esmWK, 'utf-8'), nwk = readFileSync(esmNWK, 'utf-8'); -unlinkSync(esmIndex), unlinkSync(esmWK), unlinkSync(esmNWK), unlinkSync(libIndex); -renameSync(join(libDir, 'worker.js'), join(libDir, 'worker.cjs')); -renameSync(join(libDir, 'node-worker.js'), join(libDir, 'node-worker.cjs')); +writeFileSync(join(libDir, 'worker.cjs'), readFileSync(join(libDir, 'worker.js'), 'utf-8').replace(esModule, '')); +writeFileSync(join(libDir, 'node-worker.cjs'), readFileSync(join(libDir, 'node-worker.js'), 'utf-8').replace(esModule, '')); +unlinkSync(esmIndex), unlinkSync(esmWK), unlinkSync(esmNWK), unlinkSync(libIndex), unlinkSync(libWK), unlinkSync(libNWK); unlinkSync(join(libDir, 'worker.d.ts')), unlinkSync(join(libDir, 'node-worker.d.ts')); const workerImport = /import (.*) from '\.\/node-worker';/; const workerRequire = /var (.*) = require\("\.\/node-worker"\);/; const defaultExport = /export default/; writeFileSync(join(esmDir, 'index.mjs'), esm.replace(workerImport, name => nwk.replace(defaultExport, `var ${name.slice(7, name.indexOf(' ', 8))} =`))); writeFileSync(join(esmDir, 'browser.js'), esm.replace(workerImport, name => wk.replace(defaultExport, `var ${name.slice(7, name.indexOf(' ', 8))} =`))); -writeFileSync(join(libDir, 'node.cjs'), lib.replace(workerRequire, name => nwk.replace(defaultExport, `var ${name.slice(4, name.indexOf(' ', 5))} =`))); -writeFileSync(join(libDir, 'browser.cjs'), lib.replace(workerRequire, name => wk.replace(defaultExport, `var ${name.slice(4, name.indexOf(' ', 5))} =`))); +writeFileSync(join(libDir, 'node.cjs'), lib.replace(workerRequire, name => { + name = name.slice(4, name.indexOf(' ', 5)); + return nwk.replace(defaultExport, `var ${name} = {};\n${name}["default"] =`) +})); +writeFileSync(join(libDir, 'browser.cjs'), lib.replace(workerRequire, name => { + name = name.slice(4, name.indexOf(' ', 5)); + return wk.replace(defaultExport, `var ${name} = {};\n${name}["default"] =`) +})); writeFileSync(join(libDir, 'index.cjs'), lib.replace(workerRequire, name => `var ${name.slice(4, name.indexOf(' ', 5))} = require("./node-worker.cjs");`)); \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 75625e2..6706c7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2151,11 +2151,11 @@ export function strToU8(str: string, latin1?: boolean): Uint8Array { } let c = str.charCodeAt(i); if (c < 128 || latin1) w(c); - else if (c < 2048) w(192 | (c >>> 6)), w(128 | (c & 63)); + else if (c < 2048) w(192 | (c >> 6)), w(128 | (c & 63)); else if (c > 55295 && c < 57344) c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023), - w(240 | (c >>> 18)), w(128 | ((c >>> 12) & 63)), w(128 | ((c >>> 6) & 63)), w(128 | (c & 63)); - else w(224 | (c >>> 12)), w(128 | ((c >>> 6) & 63)), w(128 | (c & 63)); + w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63)); + else w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63)); } return slc(ar, 0, ai); } @@ -2936,7 +2936,7 @@ export class AsyncUnzipInflate implements UnzipDecoder { /** * Creates a DEFLATE decompression that can be used in ZIP archives */ - constructor(_: string, sz: number) { + constructor(_: string, sz?: number) { if (sz < 320000) { this.i = new Inflate((dat, final) => { this.ondata(null, dat, final); @@ -2983,7 +2983,7 @@ export class Unzip { * @param chunk The chunk to push * @param final Whether this is the last chunk */ - push(chunk: Uint8Array, final: boolean) { + push(chunk: Uint8Array, final?: boolean) { if (!this.onfile) throw 'no callback'; if (this.c > 0) { const len = Math.min(this.c, chunk.length); @@ -3045,10 +3045,10 @@ export class Unzip { break; } else if (oc) { if (sig == 0x8074B50) { - is = i += 12 + (oc == -2 && 8), f = 2, this.c = 0; + is = i += 12 + (oc == -2 && 8), f = 3, this.c = 0; break; } else if (sig == 0x2014B50) { - is = i -= 4, f = 2, this.c = 0; + is = i -= 4, f = 3, this.c = 0; break; } }