Explorar o código

Small bugfixes (#9)

101arrowz %!s(int64=4) %!d(string=hai) anos
pai
achega
68b8a89948

+ 2 - 4
.gitignore

@@ -1,9 +1,7 @@
 node_modules/
 lib/
 esm/
-# temporary as I work on WASM
+.DS_STORE
+# Rust version - available when ready
 rs/
-rs/debug/
-rs/target/
-rs/**/*.rs.bk
 .DS_STORE

+ 2 - 1
.npmignore

@@ -5,4 +5,5 @@ test/
 .npmignore
 tsconfig.esm.json
 tsconfig.json
-yarn.lock
+yarn.lock
+rs/

+ 2 - 0
docs/classes/asyncdecompress.md

@@ -1,5 +1,7 @@
 # Class: AsyncDecompress
 
+Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
+
 ## Hierarchy
 
 * **AsyncDecompress**

+ 4 - 20
docs/classes/asyncdeflate.md

@@ -4,9 +4,7 @@ Asynchronous streaming DEFLATE compression
 
 ## Hierarchy
 
-* AsyncCmpStrm\<[DeflateOptions](../interfaces/deflateoptions.md)>
-
-  ↳ **AsyncDeflate**
+* **AsyncDeflate**
 
 ## Index
 
@@ -28,11 +26,7 @@ Asynchronous streaming DEFLATE compression
 
 \+ **new AsyncDeflate**(`opts`: [DeflateOptions](../interfaces/deflateoptions.md), `cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncDeflate](asyncdeflate.md)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous compression stream
+Creates an asynchronous DEFLATE stream
 
 #### Parameters:
 
@@ -45,11 +39,7 @@ Name | Type | Description |
 
 \+ **new AsyncDeflate**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncDeflate](asyncdeflate.md)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous compression stream
+Creates an asynchronous DEFLATE stream
 
 #### Parameters:
 
@@ -65,8 +55,6 @@ Name | Type | Description |
 
 •  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
 The handler to call whenever data is available
 
 ## Methods
@@ -75,10 +63,6 @@ The handler to call whenever data is available
 
 ▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[push](asyncdeflate.md#push)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
-
 Pushes a chunk to be deflated
 
 #### Parameters:
@@ -86,6 +70,6 @@ Pushes a chunk to be deflated
 Name | Type | Description |
 ------ | ------ | ------ |
 `chunk` | Uint8Array | The chunk to push |
-`final?` | boolean | Whether this is the final chunk  |
+`final?` | boolean | Whether this is the last chunk  |
 
 **Returns:** void

+ 6 - 14
docs/classes/asyncgunzip.md

@@ -4,9 +4,7 @@ Asynchronous streaming GZIP decompression
 
 ## Hierarchy
 
-* AsyncStrm
-
-  ↳ **AsyncGunzip**
+* **AsyncGunzip**
 
 ## Index
 
@@ -26,17 +24,15 @@ Asynchronous streaming GZIP decompression
 
 ### constructor
 
-\+ **new AsyncGunzip**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGunzip](asyncgunzip.md)
-
-*Inherited from [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
+\+ **new AsyncGunzip**(`cb`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGunzip](asyncgunzip.md)
 
-Creates an asynchronous decompression stream
+Creates an asynchronous GUNZIP stream
 
 #### Parameters:
 
 Name | Type | Description |
 ------ | ------ | ------ |
-`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is inflated  |
+`cb` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
 
 **Returns:** [AsyncGunzip](asyncgunzip.md)
 
@@ -46,8 +42,6 @@ Name | Type | Description |
 
 •  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
 The handler to call whenever data is available
 
 ## Methods
@@ -56,15 +50,13 @@ The handler to call whenever data is available
 
 ▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-*Inherited from [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
-
-Pushes a chunk to be inflated
+Pushes a chunk to be GUNZIPped
 
 #### Parameters:
 
 Name | Type | Description |
 ------ | ------ | ------ |
 `chunk` | Uint8Array | The chunk to push |
-`final?` | boolean | Whether this is the final chunk  |
+`final?` | boolean | Whether this is the last chunk  |
 
 **Returns:** void

+ 42 - 23
docs/classes/asyncgzip.md

@@ -1,15 +1,11 @@
 # Class: AsyncGzip
 
-Asynchronous streaming DEFLATE compression
-Asynchronous streaming DEFLATE compression
+Asynchronous streaming GZIP compression
+Asynchronous streaming GZIP compression
 
 ## Hierarchy
 
-* AsyncCmpStrm\<[GzipOptions](../interfaces/gzipoptions.md)>
-
-* AsyncCmpStrm\<[GzipOptions](../interfaces/gzipoptions.md)>
-
-  ↳ **AsyncGzip**
+* **AsyncGzip**
 
 ## Index
 
@@ -31,11 +27,7 @@ Asynchronous streaming DEFLATE compression
 
 \+ **new AsyncGzip**(`opts`: [GzipOptions](../interfaces/gzipoptions.md), `cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGzip](asyncgzip.md)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous compression stream
+Creates an asynchronous GZIP stream
 
 #### Parameters:
 
@@ -48,11 +40,32 @@ Name | Type | Description |
 
 \+ **new AsyncGzip**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGzip](asyncgzip.md)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
+Creates an asynchronous GZIP stream
+
+#### Parameters:
 
-*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
 
-Creates an asynchronous compression stream
+**Returns:** [AsyncGzip](asyncgzip.md)
+
+\+ **new AsyncGzip**(`opts`: [GzipOptions](../interfaces/gzipoptions.md), `cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGzip](asyncgzip.md)
+
+Creates an asynchronous GZIP stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [GzipOptions](../interfaces/gzipoptions.md) | The compression options |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [AsyncGzip](asyncgzip.md)
+
+\+ **new AsyncGzip**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGzip](asyncgzip.md)
+
+Creates an asynchronous GZIP stream
 
 #### Parameters:
 
@@ -68,10 +81,7 @@ Name | Type | Description |
 
 •  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
-*Overrides [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
+The handler to call whenever data is available
 The handler to call whenever data is available
 
 ## Methods
@@ -80,17 +90,26 @@ The handler to call whenever data is available
 
 ▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[push](asyncdeflate.md#push)*
+Pushes a chunk to be GZIPped
 
-*Overrides [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-Pushes a chunk to be deflated
+Pushes a chunk to be GZIPped
 
 #### Parameters:
 
 Name | Type | Description |
 ------ | ------ | ------ |
 `chunk` | Uint8Array | The chunk to push |
-`final?` | boolean | Whether this is the final chunk  |
+`final?` | boolean | Whether this is the last chunk  |
 
 **Returns:** void

+ 4 - 12
docs/classes/asyncinflate.md

@@ -4,9 +4,7 @@ Asynchronous streaming DEFLATE decompression
 
 ## Hierarchy
 
-* AsyncStrm
-
-  ↳ **AsyncInflate**
+* **AsyncInflate**
 
 ## Index
 
@@ -28,15 +26,13 @@ Asynchronous streaming DEFLATE decompression
 
 \+ **new AsyncInflate**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncInflate](asyncinflate.md)
 
-*Inherited from [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous decompression stream
+Creates an asynchronous inflation stream
 
 #### Parameters:
 
 Name | Type | Description |
 ------ | ------ | ------ |
-`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is inflated  |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
 
 **Returns:** [AsyncInflate](asyncinflate.md)
 
@@ -46,8 +42,6 @@ Name | Type | Description |
 
 •  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
 The handler to call whenever data is available
 
 ## Methods
@@ -56,8 +50,6 @@ The handler to call whenever data is available
 
 ▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-*Inherited from [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
-
 Pushes a chunk to be inflated
 
 #### Parameters:
@@ -65,6 +57,6 @@ Pushes a chunk to be inflated
 Name | Type | Description |
 ------ | ------ | ------ |
 `chunk` | Uint8Array | The chunk to push |
-`final?` | boolean | Whether this is the final chunk  |
+`final?` | boolean | Whether this is the last chunk  |
 
 **Returns:** void

+ 5 - 13
docs/classes/asyncunzlib.md

@@ -4,9 +4,7 @@ Asynchronous streaming Zlib decompression
 
 ## Hierarchy
 
-* AsyncStrm
-
-  ↳ **AsyncUnzlib**
+* **AsyncUnzlib**
 
 ## Index
 
@@ -28,15 +26,13 @@ Asynchronous streaming Zlib decompression
 
 \+ **new AsyncUnzlib**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncUnzlib](asyncunzlib.md)
 
-*Inherited from [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous decompression stream
+Creates an asynchronous Zlib decompression stream
 
 #### Parameters:
 
 Name | Type | Description |
 ------ | ------ | ------ |
-`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is inflated  |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
 
 **Returns:** [AsyncUnzlib](asyncunzlib.md)
 
@@ -46,8 +42,6 @@ Name | Type | Description |
 
 •  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
 The handler to call whenever data is available
 
 ## Methods
@@ -56,15 +50,13 @@ The handler to call whenever data is available
 
 ▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-*Inherited from [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
-
-Pushes a chunk to be inflated
+Pushes a chunk to be decompressed from Zlib
 
 #### Parameters:
 
 Name | Type | Description |
 ------ | ------ | ------ |
 `chunk` | Uint8Array | The chunk to push |
-`final?` | boolean | Whether this is the final chunk  |
+`final?` | boolean | Whether this is the last chunk  |
 
 **Returns:** void

+ 5 - 21
docs/classes/asynczlib.md

@@ -1,12 +1,10 @@
 # Class: AsyncZlib
 
-Asynchronous streaming DEFLATE compression
+Asynchronous streaming Zlib compression
 
 ## Hierarchy
 
-* AsyncCmpStrm\<[ZlibOptions](../interfaces/zliboptions.md)>
-
-  ↳ **AsyncZlib**
+* **AsyncZlib**
 
 ## Index
 
@@ -28,11 +26,7 @@ Asynchronous streaming DEFLATE compression
 
 \+ **new AsyncZlib**(`opts`: [ZlibOptions](../interfaces/zliboptions.md), `cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncZlib](asynczlib.md)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous compression stream
+Creates an asynchronous DEFLATE stream
 
 #### Parameters:
 
@@ -45,11 +39,7 @@ Name | Type | Description |
 
 \+ **new AsyncZlib**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncZlib](asynczlib.md)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
-
-Creates an asynchronous compression stream
+Creates an asynchronous DEFLATE stream
 
 #### Parameters:
 
@@ -65,8 +55,6 @@ Name | Type | Description |
 
 •  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
-
 The handler to call whenever data is available
 
 ## Methods
@@ -75,10 +63,6 @@ The handler to call whenever data is available
 
 ▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
 
-*Inherited from [AsyncDeflate](asyncdeflate.md).[push](asyncdeflate.md#push)*
-
-*Overrides [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
-
 Pushes a chunk to be deflated
 
 #### Parameters:
@@ -86,6 +70,6 @@ Pushes a chunk to be deflated
 Name | Type | Description |
 ------ | ------ | ------ |
 `chunk` | Uint8Array | The chunk to push |
-`final?` | boolean | Whether this is the final chunk  |
+`final?` | boolean | Whether this is the last chunk  |
 
 **Returns:** void

+ 3 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "fflate",
-  "version": "0.3.1",
+  "version": "0.3.3",
   "description": "High performance (de)compression in an 8kB package",
   "main": "lib/index.js",
   "module": "esm/index.js",
@@ -30,8 +30,9 @@
     "non-blocking"
   ],
   "scripts": {
-    "build": "yarn build:lib && yarn build:docs",
+    "build": "yarn build:lib && yarn build:docs && yarn build:post",
     "build:lib": "tsc && tsc --project tsconfig.esm.json",
+    "build:post": "node -r ts-node/register scripts/rewriteBuilds.ts",
     "build:docs": "typedoc --mode library --plugin typedoc-plugin-markdown --hideProjectName --hideBreadcrumbs --readme none --disableSources --excludePrivate --excludeProtected --out docs/ src/index.ts",
     "test": "TS_NODE_PROJECT=test/tsconfig.json uvu -b -r ts-node/register test",
     "prepack": "yarn build && yarn test"

+ 6 - 0
scripts/rewriteBuilds.ts

@@ -0,0 +1,6 @@
+import { readFileSync, writeFileSync } from 'fs';
+import { join } from 'path';
+for (const d of ['lib', 'esm']) {
+  const f = join(__dirname, '..', d, 'index.js');
+  writeFileSync(f, readFileSync(f, 'utf-8').replace(/\/\*\* \@class \*\//g, '/*#__PURE__*/'));
+}

+ 177 - 75
src/index.ts

@@ -935,7 +935,10 @@ const cbify = <T extends AsyncOptions>(dat: Uint8Array, opts: T, fns: (() => unk
     fns,
     init,
     id,
-    cb
+    (err, dat) => {
+      w.terminate();
+      cb(err, dat);
+    }
   );
   if (!opts.consume) dat = new u8(dat);
   w.postMessage([dat, opts], [dat.buffer]);
@@ -950,8 +953,10 @@ const astrm = (strm: CmpDecmpStrm) => {
   return (ev: MessageEvent<[Uint8Array, boolean]>) => strm.push(ev.data[0], ev.data[1]);
 }
 
+type Astrm = { ondata: AsyncFlateStreamHandler; push: (d: Uint8Array, f?: boolean) => void; };
+
 // async stream attach
-const astrmify = <T>(fns: (() => unknown[])[], strm: { ondata: AsyncFlateStreamHandler; push: (d: Uint8Array, f?: boolean) => void; }, opts: T | 0, init: (ev: MessageEvent<T>) => void, id: number) => {
+const astrmify = <T>(fns: (() => unknown[])[], strm: Astrm, opts: T | 0, init: (ev: MessageEvent<T>) => void, id: number) => {
   let t = 0;
   const w = wrkr<T, [Uint8Array, boolean]>(
     fns,
@@ -1028,56 +1033,21 @@ const zlv = (d: Uint8Array) => {
   if (d[1] & 32) throw 'invalid zlib data: preset dictionaries not supported';
 }
 
-abstract class AsyncStrm {
-  /**
-   * Creates an asynchronous decompression stream
-   * @param cb The callback to call whenever data is inflated
-   */
-  constructor(cb?: AsyncFlateStreamHandler) {
-    this.ondata = cb;
-    this.a();
-  }
-
-  protected abstract a(): void;
-
-  /**
-   * Pushes a chunk to be inflated
-   * @param chunk The chunk to push
-   * @param final Whether this is the final chunk
-   */
-  push(chunk: Uint8Array, final?: boolean) {};
-
-  /**
-   * The handler to call whenever data is available
-   */
-  ondata: AsyncFlateStreamHandler;
-}
-
-abstract class AsyncCmpStrm<T> extends AsyncStrm {
-  /**
-   * Creates an asynchronous compression stream
-   * @param opts The compression options
-   * @param cb The callback to call whenever data is deflated
-   */
-  constructor(opts: T, cb?: AsyncFlateStreamHandler);
-  /**
-   * Creates an asynchronous compression stream
-   * @param cb The callback to call whenever data is deflated
-   */
-  constructor(cb?: AsyncFlateStreamHandler);
-  constructor(opts?: T | AsyncFlateStreamHandler, cb?: AsyncFlateStreamHandler) {
-    if (!cb) cb = opts as AsyncFlateStreamHandler, opts = {} as T;
-    super(cb);
-    this.o = opts as T;
-  }
-
-  /**
-   * Pushes a chunk to be deflated
-   * @param chunk The chunk to push
-   * @param final Whether this is the final chunk
-   */
-  push(chunk: Uint8Array, final?: boolean) {};
-  protected o: T;
+/**
+ * Creates an asynchronous compression stream
+ * @param opts The compression options
+ * @param cb The callback to call whenever data is deflated
+ */
+function AsyncCmpStrm<T>(opts: T, cb?: AsyncFlateStreamHandler): T;
+/**
+ * Creates an asynchronous compression stream
+ * @param cb The callback to call whenever data is deflated
+ */
+function AsyncCmpStrm<T>(cb?: AsyncFlateStreamHandler): T;
+function AsyncCmpStrm<T>(opts?: T | AsyncFlateStreamHandler, cb?: AsyncFlateStreamHandler): T {
+  if (!cb) cb = opts as AsyncFlateStreamHandler, opts = {} as T;
+  this.ondata = cb as AsyncFlateStreamHandler;
+  return opts as T;
 }
 
 // zlib footer: -4 to -0 is Adler32
@@ -1125,16 +1095,40 @@ export class Deflate {
 /**
  * Asynchronous streaming DEFLATE compression
  */
-export class AsyncDeflate extends AsyncCmpStrm<DeflateOptions> {
-  protected a() {
+export class AsyncDeflate {
+  /**
+   * The handler to call whenever data is available
+   */
+  ondata: AsyncFlateStreamHandler;
+
+  /**
+   * Creates an asynchronous DEFLATE stream
+   * @param opts The compression options
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(opts: DeflateOptions, cb?: AsyncFlateStreamHandler);
+  /**
+   * Creates an asynchronous DEFLATE stream
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(cb?: AsyncFlateStreamHandler);
+  constructor(opts?: DeflateOptions | AsyncFlateStreamHandler, cb?: AsyncFlateStreamHandler) {
     astrmify([
       bDflt,
       () => [astrm, Deflate]
-    ], this, this.o, ev => {
-      const strm = new Deflate(ev.data);
+    ], this as unknown as Astrm, AsyncCmpStrm.call(this, opts, cb), ev => {
+      const strm = new Deflate(ev.data, true as unknown as FlateStreamHandler);
       onmessage = astrm(strm);
     }, 6);
   }
+
+  /**
+   * Pushes a chunk to be deflated
+   * @param chunk The chunk to push
+   * @param final Whether this is the last chunk
+   */
+  // @ts-ignore
+  push(chunk: Uint8Array, final?: boolean): void;
 }
 
 /**
@@ -1218,16 +1212,34 @@ export class Inflate {
 /**
  * Asynchronous streaming DEFLATE decompression
  */
-export class AsyncInflate extends AsyncStrm {
-  protected a() {
+export class AsyncInflate {
+  /**
+   * The handler to call whenever data is available
+   */
+  ondata: AsyncFlateStreamHandler;
+
+  /**
+   * Creates an asynchronous inflation stream
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(cb?: AsyncFlateStreamHandler) {
+    this.ondata = cb;
     astrmify([
       bInflt,
       () => [astrm, Inflate]
-    ], this, 0, () => {
+    ], this as unknown as Astrm, 0, () => {
       const strm = new Inflate();
       onmessage = astrm(strm);
     }, 7);
   }
+
+  /**
+   * Pushes a chunk to be inflated
+   * @param chunk The chunk to push
+   * @param final Whether this is the last chunk
+   */
+  // @ts-ignore
+  push(chunk: Uint8Array, final?: boolean): void;
 }
 
 /**
@@ -1313,19 +1325,43 @@ export class Gzip {
 }
 
 /**
- * Asynchronous streaming DEFLATE compression
+ * Asynchronous streaming GZIP compression
  */
-export class AsyncGzip extends AsyncCmpStrm<GzipOptions> {
-  protected a() {
+export class AsyncGzip {
+  /**
+   * The handler to call whenever data is available
+   */
+  ondata: AsyncFlateStreamHandler;
+
+  /**
+   * Creates an asynchronous GZIP stream
+   * @param opts The compression options
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(opts: GzipOptions, cb?: AsyncFlateStreamHandler);
+  /**
+   * Creates an asynchronous GZIP stream
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(cb?: AsyncFlateStreamHandler);
+  constructor(opts?: GzipOptions | AsyncFlateStreamHandler, cb?: AsyncFlateStreamHandler) {
     astrmify([
       bDflt,
       gze,
       () => [astrm, Deflate, Gzip]
-    ], this, this.o, ev => {
-      const strm = new Gzip(ev.data);
+    ], this as unknown as Astrm, AsyncCmpStrm.call(this, opts, cb), ev => {
+      const strm = new Gzip(ev.data, true as unknown as FlateStreamHandler);
       onmessage = astrm(strm);
     }, 8);
   }
+
+  /**
+   * Pushes a chunk to be GZIPped
+   * @param chunk The chunk to push
+   * @param final Whether this is the last chunk
+   */
+  // @ts-ignore
+  push(chunk: Uint8Array, final?: boolean): void;
 }
 
 /**
@@ -1408,17 +1444,35 @@ export class Gunzip {
 /**
  * Asynchronous streaming GZIP decompression
  */
-export class AsyncGunzip extends AsyncStrm {
-  protected a() {
+export class AsyncGunzip {
+  /**
+   * The handler to call whenever data is available
+   */
+  ondata: AsyncFlateStreamHandler;
+
+  /**
+   * Creates an asynchronous GUNZIP stream
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(cb: AsyncFlateStreamHandler) {
+    this.ondata = cb;
     astrmify([
       bInflt,
       guze,
       () => [astrm, Inflate, Gunzip]
-    ], this, 0, () => {
+    ], this as unknown as Astrm, 0, () => {
       const strm = new Gunzip();
       onmessage = astrm(strm);
     }, 9);
   }
+
+  /**
+   * Pushes a chunk to be GUNZIPped
+   * @param chunk The chunk to push
+   * @param final Whether this is the last chunk
+   */
+  // @ts-ignore
+  push(chunk: Uint8Array, final?: boolean): void;
 }
 
 /**
@@ -1502,19 +1556,43 @@ export class Zlib {
 }
 
 /**
- * Asynchronous streaming DEFLATE compression
+ * Asynchronous streaming Zlib compression
  */
-export class AsyncZlib extends AsyncCmpStrm<ZlibOptions> {
-  protected a() {
+export class AsyncZlib {
+  /**
+   * The handler to call whenever data is available
+   */
+  ondata: AsyncFlateStreamHandler;
+
+  /**
+   * Creates an asynchronous DEFLATE stream
+   * @param opts The compression options
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(opts: ZlibOptions, cb?: AsyncFlateStreamHandler);
+  /**
+   * Creates an asynchronous DEFLATE stream
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(cb?: AsyncFlateStreamHandler);
+  constructor(opts?: ZlibOptions | AsyncFlateStreamHandler, cb?: AsyncFlateStreamHandler) {
     astrmify([
       bDflt,
       zle,
       () => [astrm, Deflate, Zlib]
-    ], this, this.o, ev => {
-      const strm = new Zlib(ev.data);
+    ], this as unknown as Astrm, AsyncCmpStrm.call(this, opts, cb), ev => {
+      const strm = new Zlib(ev.data, true as unknown as FlateStreamHandler);
       onmessage = astrm(strm);
     }, 10);
   }
+
+  /**
+   * Pushes a chunk to be deflated
+   * @param chunk The chunk to push
+   * @param final Whether this is the last chunk
+   */
+  // @ts-ignore
+  push(chunk: Uint8Array, final?: boolean): void;
 }
 
 /**
@@ -1594,17 +1672,35 @@ export class Unzlib {
 /**
  * Asynchronous streaming Zlib decompression
  */
-export class AsyncUnzlib extends AsyncStrm {
-  protected a() {
+export class AsyncUnzlib {
+  /**
+   * The handler to call whenever data is available
+   */
+  ondata: AsyncFlateStreamHandler;
+
+  /**
+   * Creates an asynchronous Zlib decompression stream
+   * @param cb The callback to call whenever data is deflated
+   */
+  constructor(cb?: AsyncFlateStreamHandler) {
+    this.ondata = cb;
     astrmify([
       bInflt,
       zule,
       () => [astrm, Inflate, Unzlib]
-    ], this, 0, () => {
+    ], this as unknown as Astrm, 0, () => {
       const strm = new Unzlib();
       onmessage = astrm(strm);
     }, 11);
   }
+
+  /**
+   * Pushes a chunk to be decompressed from Zlib
+   * @param chunk The chunk to push
+   * @param final Whether this is the last chunk
+   */
+  // @ts-ignore
+  push(chunk: Uint8Array, final?: boolean): void;
 }
 
 /**
@@ -1693,6 +1789,9 @@ export class Decompress {
   }
 }
 
+/**
+ * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
+ */
 export class AsyncDecompress {
   private G = AsyncGunzip;
   private I = AsyncInflate;
@@ -1962,6 +2061,7 @@ export function zip(data: AsyncZippable, opts: AsyncZipOptions | FlateCallback,
     wzf(out, o, files.length, cdl, oe);
     cb(null, out);
   }
+  if (!lft) cbf();
   // Cannot use lft because it can decrease
   for (let i = 0; i < slft; ++i) {
     const fn = k[i];
@@ -2057,6 +2157,7 @@ export function unzip(data: Uint8Array, cb: UnzipCallback): AsyncTerminable {
   let e = data.length - 22;
   while (b4(data, e) != 0x6054B50) --e;
   let lft = b2(data, e + 8);
+  if (!lft) cb(null, {});
   const c = lft;
   let o = b4(data, e + 16);
   for (let i = 0; i < c; ++i) {
@@ -2092,6 +2193,7 @@ export function unzipSync(data: Uint8Array) {
   let e = data.length - 22;
   while (b4(data, e) != 0x6054B50) --e;
   const c = b2(data, e + 8);
+  if (!c) return {};
   let o = b4(data, e + 16);
   for (let i = 0; i < c; ++i) {
     const off = b4(data, o + 42);

+ 1 - 1
tsconfig.esm.json

@@ -3,7 +3,7 @@
   "compilerOptions": {
     "declaration": false,
     "moduleResolution": "node",
-    "target": "ES2018",
+    "module": "ESNext",
     "outDir": "esm"
   }
 }