فهرست منبع

Added sync and async streaming; removed bloat
- Autogenerate worker strings, even in minified code
- Add error checking support
- Improve performance

Arjun Barrett 4 سال پیش
والد
کامیت
c23d56f29d

+ 154 - 49
README.md

@@ -4,19 +4,21 @@ High performance (de)compression in an 8kB package
 ## Why fflate?
 `fflate` (short for fast flate) is the **fastest, smallest, and most versatile** pure JavaScript compression and decompression library in existence, handily beating [`pako`](https://npmjs.com/package/pako), [`tiny-inflate`](https://npmjs.com/package/tiny-inflate), and [`UZIP.js`](https://github.com/photopea/UZIP.js) in performance benchmarks while being multiple times more lightweight. Its compression ratios are often better than even the original Zlib C library. It includes support for DEFLATE, GZIP, and Zlib data. Data compressed by `fflate` can be decompressed by other tools, and vice versa.
 
-In addition to the base decompression and compression APIs, `fflate` supports high-speed ZIP compression and decompression for an extra 3 kB. In fact, the compressor, in synchronous mode, compresses both more quickly and with a higher compression ratio than most compression software (even Info-ZIP, a C program), and in asynchronous mode it can utilize multiple cores to achieve over 3x the performance of any other utility.
-
-|                           | `pako` | `tiny-inflate`       | `UZIP.js`             | `fflate`                       |
-|---------------------------|--------|----------------------|-----------------------|--------------------------------|
-| Decompression performance | 1x     | Up to 40% slower     | **Up to 40% faster**  | **Up to 40% faster**           |
-| Compression performance   | 1x     | N/A                  | Up to 5% faster       | **Up to 50% faster**           |
-| Bundle size (minified)    | 45.6kB | **3kB**              | 14.2kB                | 8kB **(3kB for only inflate)** |
-| Compression support       | ✅     | ❌                    | ✅                    | ✅                             |
-| ZIP support               | ❌     | ❌                    | ✅                    | ✅                             |
-| Thread/Worker safe        | ✅     | ✅                    | ❌                    | ✅                             |
-| GZIP/Zlib support         | ✅     | ❌                    | ❌                    | ✅                             |
-| Multi-core/Asynchronous   | ❌     | ❌                    | ❌                    | ✅                             |
-| Uses ES Modules           | ❌     | ❌                    | ❌                    | ✅                             |
+In addition to the base decompression and compression APIs, `fflate` supports high-speed ZIP compression and decompression for an extra 3 kB. In fact, the compressor, in synchronous mode, compresses both more quickly and with a higher compression ratio than most compression software (even Info-ZIP, a C program), and in asynchronous mode it can utilize multiple threads to achieve over 3x the performance of any other utility.
+
+|                             | `pako` | `tiny-inflate`         | `UZIP.js`             | `fflate`                       |
+|-----------------------------|--------|------------------------|-----------------------|--------------------------------|
+| Decompression performance   | 1x     | Up to 40% slower       | **Up to 40% faster**  | **Up to 40% faster**           |
+| Compression performance     | 1x     | N/A                    | Up to 5% faster       | **Up to 50% faster**           |
+| Base bundle size (minified) | 45.6kB | **3kB (inflate only)** | 14.2kB                | 8kB **(3kB for inflate only)** |
+| Compression support         | ✅     | ❌                      | ✅                    | ✅                             |
+| Thread/Worker safe          | ✅     | ✅                      | ❌                    | ✅                             |
+| ZIP support                 | ❌     | ❌                      | ✅                    | ✅                             |
+| Streaming support           | ✅     | ❌                      | ❌                    | ✅                             |
+| GZIP/Zlib support           | ✅     | ❌                      | ❌                    | ✅                             |
+| Doesn't hang on error       | ✅     | ❌                      | ❌                    | ✅                             |
+| Multi-thread/Asynchronous   | ❌     | ❌                      | ❌                    | ✅                             |
+| Uses ES Modules             | ❌     | ❌                      | ❌                    | ✅                             |
 
 ## Usage
 
@@ -27,13 +29,19 @@ npm i fflate # or yarn add fflate, or pnpm add fflate
 
 Import:
 ```js
+// I will assume that you use the following for the rest of this guide
 import * as fflate from 'fflate';
-// ALWAYS import only what you need to minimize bundle size.
+
+// However, you should import ONLY what you need to minimize bloat.
 // So, if you just need GZIP compression support:
 import { gzipSync } from 'fflate';
+// Woo! You just saved 20 kB off your bundle with one line.
 ```
+
 If your environment doesn't support ES Modules (e.g. Node.js):
 ```js
+// Try to avoid this when using fflate in the browser, as it will import
+// all of fflate's components, even those that you aren't using.
 const fflate = require('fflate');
 ```
 
@@ -53,6 +61,13 @@ const massiveFile = new Uint8Array(massiveFileBuf);
 // The default level is 6
 const notSoMassive = fflate.zlibSync(massiveFile, { level: 9 });
 const massiveAgain = fflate.unzlibSync(notSoMassive);
+const gzipped = fflate.gzipSync(massiveFile, {
+  // GZIP-specific: the filename to use when decompressed
+  filename: 'aMassiveFile.txt',
+  // GZIP-specific: the modification time. Can be a Date, date string,
+  // or Unix timestamp
+  mtime: '9/1/16 2:00 PM'
+});
 ```
 `fflate` can autodetect a compressed file's format as well:
 ```js
@@ -65,10 +80,9 @@ const compressed = new Uint8Array(
 const decompressed = fflate.decompressSync(compressed);
 ```
 
-Using strings is easy with `TextEncoder` and `TextDecoder`:
+Using strings is easy with `fflate`'s string conversion API:
 ```js
-const enc = new TextEncoder(), dec = new TextDecoder();
-const buf = enc.encode('Hello world!');
+const buf = fflate.strToU8('Hello world!');
 
 // The default compression method is gzip
 // Increasing mem may increase performance at the cost of memory
@@ -77,32 +91,78 @@ const compressed = fflate.compressSync(buf, { level: 6, mem: 8 });
 
 // When you need to decompress:
 const decompressed = fflate.decompressSync(compressed);
-const origText = dec.decode(decompressed);
+const origText = fflate.strFromU8(decompressed);
 console.log(origText); // Hello world!
 ```
-If you're using an older browser, only want ASCII, or need to encode the compressed data itself as a string, you can use the following methods:
+
+If you need to use an (albeit inefficient) binary string, you can set the second argument to `true`.
 ```js
-// data to string
-const dts = data => {
-  let result = '';
-  for (let value of data)
-    result += String.fromCharCode(data);
-  return result;
-}
-// string to data
-const std = str => {
-  let result = new Uint8Array(str.length);
-  for (let i = 0; i < str.length; ++i)
-    result[i] = str.charCodeAt(i);
-  return result;
-}
-const buf = std('Hello world!');
-// Note that compressed data strings are much less efficient than raw binary
-const compressedString = dts(fflate.compressSync(buf));
-const decompressed = fflate.decompressSync(std(compressedString));
-const origText = dts(decompressed);
+const buf = fflate.strToU8('Hello world!');
+
+// The second argument, latin1, is a boolean that indicates that the data
+// is not Unicode but rather should be encoded and decoded as Latin-1.
+const compressedString = fflate.strFromU8(
+  fflate.compressSync(buf),
+  true
+);
+const decompressed = fflate.decompressSync(
+  fflate.strToU8(compressedString, true)
+);
+const origText = fflate.strFromU8(decompressed);
 console.log(origText); // Hello world!
 ```
+
+You can use streams as well to incrementally add data to be compressed or decompressed:
+```js
+// This example uses synchronous streams, but for the best experience
+// you'll definitely want to use asynchronous streams.
+
+let outStr = '';
+const gzipStream = new fflate.Gzip({ level: 9 }, (chunk, isLast) => {
+  // accumulate in an inefficient binary string (just an example)
+  outStr += fflate.strFromU8(chunk, true);
+});
+
+// You can also attach the data handler separately if you don't want to
+// do so in the constructor.
+gzipStream.ondata = (chunk, final) => { ... }
+
+// Since this is synchronous, all errors will be thrown by stream.push()
+gzipStream.push(chunk1);
+gzipStream.push(chunk2);
+
+...
+
+// You should mark the last chunk by using true in the second argument
+// In addition to being necessary for the stream to work properly, this
+// will also set the isLast parameter in the handler to true.
+gzipStream.push(lastChunk, true);
+
+console.log(outStr); // The compressed binary string is now available
+
+// The options parameter for compression streams is optional; you can
+// provide one parameter (the handler) or none at all if you set
+// deflateStream.ondata later.
+const deflateStream = new fflate.Deflate((chunk, final) => {
+  console.log(chunk, final);
+});
+
+const inflateStream = new fflate.Inflate();
+inflateStream.ondata = (decompressedChunk, final) => {
+  // print out a string of the compressed data
+  console.log(fflate.strFromU8(decompressedChunk));
+};
+
+// Decompress streams auto-detect the compression method, as the
+// non-streaming decompress() method does.
+const dcmpStrm = new fflate.Decompress((chunk, final) => {
+  console.log(
+    'This chunk was encoded in either GZIP, Zlib, or DEFLATE',
+    chunk
+  );
+});
+```
+
 You can create multi-file ZIP archives easily as well:
 ```js
 // Note that the asynchronous version (see below) runs in parallel and
@@ -145,21 +205,19 @@ const decompressed = fflate.unzipSync(zipped);
 ```
 As you may have guessed, there is an asynchronous version of every method as well. Unlike most libraries, this will cause the compression or decompression run in a separate thread entirely and automatically by using Web (or Node) Workers. This means that the processing will not block the main thread at all.
 
-Note that there is a significant initial overhead to using workers of about 70ms, so it's best to avoid the asynchronous API unless necessary.
-
-For data under about 2MB, the main thread is blocked for so short a time (under 100ms) during both compression and decompression that most users cannot notice it anyway, so using the synchronous API is better. However, if you're compressing multiple files at once, or are compressing large amounts of data, the callback APIs are an order of magnitude better.
+Note that there is a significant initial overhead to using workers of about 70ms, so it's best to avoid the asynchronous API unless necessary. However, if you're compressing multiple large files at once, or the synchronous API causes the main thread to hang for too long, the callback APIs are an order of magnitude better.
 ```js
-import { gzip, zlib, zip } from 'fflate';
+import { gzip, zlib, AsyncGzip, zip } from 'fflate';
 
-// Workers will work in almost any browser (even IE10!)
+// Workers will work in almost any browser (even IE11!)
 // However, they fail below Node v12 without the --experimental-worker
 // CLI flag, and will fail entirely on Node below v10.
 
 // All of the async APIs use a node-style callback as so:
 const terminate = gzip(aMassiveFile, (err, data) => {
   if (err) {
-    // Note that for now, this rarely, if ever, happens. This will only
-    // occur upon an exception in the worker (which is typically a bug).
+    // The compressed data was likely corrupt, so we have to handle
+    // the error.
     return;
   }
   // Use data however you like
@@ -173,24 +231,69 @@ if (needToCancel) {
   terminate();
 }
 
+// If you wish to provide options, use the second argument.
+
 // The consume option will render the data inside aMassiveFile unusable,
 // but can dramatically improve performance and reduce memory usage.
 zlib(aMassiveFile, { consume: true, level: 9 }, (err, data) => {
   // Use the data
 });
 
+// Asynchronous streams are similar to synchronous streams, but the
+// handler has the error that occurred (if any) as the first parameter,
+// and they don't block the main thread.
+
+// Additionally, any buffers that are pushed in will be consumed and
+// rendered unusable; if you need to use a buffer you push in, you
+// should clone it first.
+const gzs = new AsyncGzip({ level: 9, mem: 12, filename: 'hello.txt' });
+let wasCallbackCalled = false;
+gzs.ondata = (err, chunk, final) => {
+  // Note the new err parameter
+  if (err) {
+    // Note that after this occurs, the stream becomes corrupt and must
+    // be discarded. You can't continue pushing chunks and expect it to
+    // work.
+    console.error(err);
+    return;
+  }
+  wasCallbackCalled = true;
+}
+gzs.push(chunk);
+
+// Since the stream is asynchronous, the callback will not be called
+// immediately. If such behavior is absolutely necessary (it shouldn't
+// be), use synchronous streams.
+console.log(wasCallbackCalled) // false
+
 // This is way faster than zipSync because the compression of multiple
 // files runs in parallel. In fact, the fact that it's parallelized
-// makes it faster than most standalone ZIP CLIs.
+// makes it faster than most standalone ZIP CLIs. The effect is most
+// significant for multiple large files; less so for many small ones.
 zip({ f1: aMassiveFile, 'f2.txt': anotherMassiveFile }, (err, data) => {
   // Save the ZIP file
 })
 ```
 
-Try not to use *both* the asynchronous and synchronous APIs. They are about 9kB and 8kB individually, but using them both leads to a 16kB bundle (as you can see from [Bundlephobia](https://bundlephobia.com/result?p=fflate)).
-
 See the [documentation](https://github.com/101arrowz/fflate/blob/master/docs/README.md) for more detailed information about the API.
 
+## Bundle size estimates
+
+Since `fflate` uses ES Modules, this table should give you a general idea of `fflate`'s bundle size for the features you need. The maximum bundle size that is possible with `fflate` is about 22kB if you use every single feature, but feature parity with `pako` is only around 10kB (as opposed to 45kB from `pako`). If your bundle size increases dramatically after adding `fflate`, please [create an issue](https://github.com/101arrowz/fflate/issues/new).
+
+| Feature                 | Bundle size (minified)         | Nearest competitor     |
+|-------------------------|--------------------------------|------------------------|
+| Decompression           | 3kB                            | `tiny-inflate`         |
+| Compression             | 5kB                            | `UZIP.js`, 184% larger |
+| Async decompression     | 4kB (1kB + raw decompression)  | N/A                    |
+| Async compression       | 5kB (1kB + raw compression)    | N/A                    |
+| ZIP decompression       | 5kB (2kB + raw decompression)  | `UZIP.js`, 184% larger |
+| ZIP compression         | 7kB (2kB + raw compression)    | `UZIP.js`, 103% larger |
+| GZIP/Zlib decompression | 4kB (1kB + raw decompression)  | `pako`, 1040% larger   |
+| GZIP/Zlib compression   | 5kB (1kB + raw compression)    | `pako`, 812% larger    |
+| Streaming decompression | 4kB (1kB + raw decompression)  | `pako`, 1040% larger   |
+| Streaming compression   | 5kB (1kB + raw compression)    | `pako`, 812% larger    |
+
 ## What makes `fflate` so fast?
 Many JavaScript compression/decompression libraries exist. However, the most popular one, [`pako`](https://npmjs.com/package/pako), is merely a clone of Zlib rewritten nearly line-for-line in JavaScript. Although it is by no means poorly made, `pako` doesn't recognize the many differences between JavaScript and C, and therefore is suboptimal for performance. Moreover, even when minified, the library is 45 kB; it may not seem like much, but for anyone concerned with optimizing bundle size (especially library authors), it's more weight than necessary.
 
@@ -198,7 +301,7 @@ Note that there exist some small libraries like [`tiny-inflate`](https://npmjs.c
 
 [`UZIP.js`](https://github.com/photopea/UZIP.js) is both faster (by up to 40%) and smaller (14 kB minified) than `pako`, and it contains a variety of innovations that make it excellent for both performance and compression ratio. However, the developer made a variety of tiny mistakes and inefficient design choices that make it imperfect. Moreover, it does not support GZIP or Zlib data directly; one must remove the headers manually to use `UZIP.js`.
 
-So what makes `fflate` different? It takes the brilliant innovations of `UZIP.js` and optimizes them while adding direct support for GZIP and Zlib data. And unlike all of the above libraries, it uses ES Modules to allow for partial builds through tree shaking, meaning that it can rival even `tiny-inflate` in size while maintaining excellent performance. The end result is a library that, in total, weighs 8kB minified for the entire build (3kB for decompression only and 5kB for compression only), is about 15% faster than `UZIP.js` or up to 60% faster than `pako`, and achieves the same or better compression ratio than the rest.
+So what makes `fflate` different? It takes the brilliant innovations of `UZIP.js` and optimizes them while adding direct support for GZIP and Zlib data. And unlike all of the above libraries, it uses ES Modules to allow for partial builds through tree shaking, meaning that it can rival even `tiny-inflate` in size while maintaining excellent performance. The end result is a library that, in total, weighs 8kB minified for the core build (3kB for decompression only and 5kB for compression only), is about 15% faster than `UZIP.js` or up to 60% faster than `pako`, and achieves the same or better compression ratio than the rest.
 
 Before you decide that `fflate` is the end-all compression library, you should note that JavaScript simply cannot rival the performance of a compiled language. If you're willing to have 160 kB of extra weight and [much less browser support](https://caniuse.com/wasm), you can achieve  more performance than `fflate` with a WASM build of Zlib like [`wasm-flate`](https://www.npmjs.com/package/wasm-flate). And if you're only using Node.js, just use the [native Zlib bindings](https://nodejs.org/api/zlib.html) that offer the best performance. Though note that even against these compiled libraries, `fflate` is only around 30% slower in decompression and 10% slower in compression, and can still achieve better compression ratios!
 
@@ -212,5 +315,7 @@ Other than that, `fflate` is completely ES3, meaning you probably won't even nee
 ## Testing
 You can validate the performance of `fflate` with `npm`/`yarn`/`pnpm` `test`. It validates that the module is working as expected, ensures the outputs are no more than 5% larger than competitors at max compression, and outputs performance metrics to `test/results`.
 
+Note that the time it takes for the CLI to show the completion of each test is not representative of the time each package took, so please check the JSON output if you want accurate masurements.
+
 ## License
 MIT

+ 98 - 17
docs/README.md

@@ -2,6 +2,23 @@
 
 ## Index
 
+### Classes
+
+* [AsyncDecompress](classes/asyncdecompress.md)
+* [AsyncDeflate](classes/asyncdeflate.md)
+* [AsyncGunzip](classes/asyncgunzip.md)
+* [AsyncGzip](classes/asyncgzip.md)
+* [AsyncInflate](classes/asyncinflate.md)
+* [AsyncUnzlib](classes/asyncunzlib.md)
+* [AsyncZlib](classes/asynczlib.md)
+* [Decompress](classes/decompress.md)
+* [Deflate](classes/deflate.md)
+* [Gunzip](classes/gunzip.md)
+* [Gzip](classes/gzip.md)
+* [Inflate](classes/inflate.md)
+* [Unzlib](classes/unzlib.md)
+* [Zlib](classes/zlib.md)
+
 ### Interfaces
 
 * [AsyncDeflateOptions](interfaces/asyncdeflateoptions.md)
@@ -22,8 +39,10 @@
 
 ### Type aliases
 
+* [AsyncFlateStreamHandler](README.md#asyncflatestreamhandler)
 * [AsyncZippableFile](README.md#asynczippablefile)
 * [FlateCallback](README.md#flatecallback)
+* [FlateStreamHandler](README.md#flatestreamhandler)
 * [UnzipCallback](README.md#unzipcallback)
 * [ZippableFile](README.md#zippablefile)
 
@@ -39,6 +58,8 @@
 * [gzipSync](README.md#gzipsync)
 * [inflate](README.md#inflate)
 * [inflateSync](README.md#inflatesync)
+* [strFromU8](README.md#strfromu8)
+* [strToU8](README.md#strtou8)
 * [unzip](README.md#unzip)
 * [unzipSync](README.md#unzipsync)
 * [unzlib](README.md#unzlib)
@@ -50,6 +71,20 @@
 
 ## Type aliases
 
+### AsyncFlateStreamHandler
+
+Ƭ  **AsyncFlateStreamHandler**: (err: Error,data: Uint8Array,final: boolean) => void
+
+Handler for asynchronous data (de)compression streams
+
+**`param`** Any error that occurred
+
+**`param`** The data output from the stream processor
+
+**`param`** Whether this is the final block
+
+___
+
 ### AsyncZippableFile
 
 Ƭ  **AsyncZippableFile**: Uint8Array \| []
@@ -60,7 +95,7 @@ ___
 
 ### FlateCallback
 
-Ƭ  **FlateCallback**: (err: Error,data: Uint8Array) => unknown
+Ƭ  **FlateCallback**: (err: Error,data: Uint8Array) => void
 
 Callback for asynchronous (de)compression methods
 
@@ -70,9 +105,21 @@ Callback for asynchronous (de)compression methods
 
 ___
 
+### FlateStreamHandler
+
+Ƭ  **FlateStreamHandler**: (data: Uint8Array,final: boolean) => void
+
+Handler for data (de)compression streams
+
+**`param`** The data output from the stream processor
+
+**`param`** Whether this is the final block
+
+___
+
 ### UnzipCallback
 
-Ƭ  **UnzipCallback**: (err: Error,data: [Unzipped](interfaces/unzipped.md)) => unknown
+Ƭ  **UnzipCallback**: (err: Error,data: [Unzipped](interfaces/unzipped.md)) => void
 
 Callback for asynchronous ZIP decompression
 
@@ -171,16 +218,16 @@ ___
 
 ### deflateSync
 
-▸ **deflateSync**(`data`: Uint8Array, `opts?`: [DeflateOptions](interfaces/deflateoptions.md)): Uint8Array
+▸ **deflateSync**(`data`: Uint8Array, `opts`: [DeflateOptions](interfaces/deflateoptions.md)): Uint8Array
 
 Compresses data with DEFLATE without any wrapper
 
 #### Parameters:
 
-Name | Type | Description |
------- | ------ | ------ |
-`data` | Uint8Array | The data to compress |
-`opts?` | [DeflateOptions](interfaces/deflateoptions.md) | The compression options |
+Name | Type | Default value | Description |
+------ | ------ | ------ | ------ |
+`data` | Uint8Array | - | The data to compress |
+`opts` | [DeflateOptions](interfaces/deflateoptions.md) | {} | The compression options |
 
 **Returns:** Uint8Array
 
@@ -294,16 +341,16 @@ ___
 
 ### gzipSync
 
-▸ **gzipSync**(`data`: Uint8Array, `opts?`: [GzipOptions](interfaces/gzipoptions.md)): Uint8Array
+▸ **gzipSync**(`data`: Uint8Array, `opts`: [GzipOptions](interfaces/gzipoptions.md)): Uint8Array
 
 Compresses data with GZIP
 
 #### Parameters:
 
-Name | Type | Description |
------- | ------ | ------ |
-`data` | Uint8Array | The data to compress |
-`opts?` | [GzipOptions](interfaces/gzipoptions.md) | The compression options |
+Name | Type | Default value | Description |
+------ | ------ | ------ | ------ |
+`data` | Uint8Array | - | The data to compress |
+`opts` | [GzipOptions](interfaces/gzipoptions.md) | {} | The compression options |
 
 **Returns:** Uint8Array
 
@@ -357,6 +404,40 @@ Name | Type | Description |
 
 ___
 
+### strFromU8
+
+▸ **strFromU8**(`dat`: Uint8Array, `latin1?`: boolean): string
+
+Converts a Uint8Array to a string
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`dat` | Uint8Array | The data to decode to string |
+`latin1?` | boolean | Whether or not to interpret the data as Latin-1. This should               not need to be true unless encoding to binary string. |
+
+**Returns:** string
+
+___
+
+### strToU8
+
+▸ **strToU8**(`str`: string, `latin1?`: boolean): Uint8Array
+
+Converts a string into a Uint8Array for use with compression/decompression methods
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`str` | string | The string to encode |
+`latin1?` | boolean | Whether or not to interpret the data as Latin-1. This should               not need to be true unless decoding a binary string. |
+
+**Returns:** Uint8Array
+
+___
+
 ### unzip
 
 ▸ **unzip**(`data`: Uint8Array, `cb`: [UnzipCallback](README.md#unzipcallback)): [AsyncTerminable](interfaces/asyncterminable.md)
@@ -520,15 +601,15 @@ ___
 
 ### zlibSync
 
-▸ **zlibSync**(`data`: Uint8Array, `opts?`: [ZlibOptions](interfaces/zliboptions.md)): Uint8Array
+▸ **zlibSync**(`data`: Uint8Array, `opts`: [ZlibOptions](interfaces/zliboptions.md)): Uint8Array
 
 Compress data with Zlib
 
 #### Parameters:
 
-Name | Type | Description |
------- | ------ | ------ |
-`data` | Uint8Array | The data to compress |
-`opts?` | [ZlibOptions](interfaces/zliboptions.md) | The compression options |
+Name | Type | Default value | Description |
+------ | ------ | ------ | ------ |
+`data` | Uint8Array | - | The data to compress |
+`opts` | [ZlibOptions](interfaces/zliboptions.md) | {} | The compression options |
 
 **Returns:** Uint8Array

+ 60 - 0
docs/classes/asyncdecompress.md

@@ -0,0 +1,60 @@
+# Class: AsyncDecompress
+
+## Hierarchy
+
+* **AsyncDecompress**
+
+## Index
+
+### Constructors
+
+* [constructor](asyncdecompress.md#constructor)
+
+### Properties
+
+* [ondata](asyncdecompress.md#ondata)
+
+### Methods
+
+* [push](asyncdecompress.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new AsyncDecompress**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncDecompress](asyncdecompress.md)
+
+Creates an asynchronous decompression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is decompressed  |
+
+**Returns:** [AsyncDecompress](asyncdecompress.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be decompressed
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 91 - 0
docs/classes/asyncdeflate.md

@@ -0,0 +1,91 @@
+# Class: AsyncDeflate
+
+Asynchronous streaming DEFLATE compression
+
+## Hierarchy
+
+* AsyncCmpStrm\<[DeflateOptions](../interfaces/deflateoptions.md)>
+
+  ↳ **AsyncDeflate**
+
+## Index
+
+### Constructors
+
+* [constructor](asyncdeflate.md#constructor)
+
+### Properties
+
+* [ondata](asyncdeflate.md#ondata)
+
+### Methods
+
+* [push](asyncdeflate.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **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
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [DeflateOptions](../interfaces/deflateoptions.md) | The compression options |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [AsyncDeflate](asyncdeflate.md)
+
+\+ **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
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [AsyncDeflate](asyncdeflate.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
+
+*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **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:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 70 - 0
docs/classes/asyncgunzip.md

@@ -0,0 +1,70 @@
+# Class: AsyncGunzip
+
+Asynchronous streaming GZIP decompression
+
+## Hierarchy
+
+* AsyncStrm
+
+  ↳ **AsyncGunzip**
+
+## Index
+
+### Constructors
+
+* [constructor](asyncgunzip.md#constructor)
+
+### Properties
+
+* [ondata](asyncgunzip.md#ondata)
+
+### Methods
+
+* [push](asyncgunzip.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new AsyncGunzip**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncGunzip](asyncgunzip.md)
+
+*Inherited from [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
+
+Creates an asynchronous decompression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is inflated  |
+
+**Returns:** [AsyncGunzip](asyncgunzip.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
+
+*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+*Inherited from [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
+
+Pushes a chunk to be inflated
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 96 - 0
docs/classes/asyncgzip.md

@@ -0,0 +1,96 @@
+# Class: AsyncGzip
+
+Asynchronous streaming DEFLATE compression
+Asynchronous streaming DEFLATE compression
+
+## Hierarchy
+
+* AsyncCmpStrm\<[GzipOptions](../interfaces/gzipoptions.md)>
+
+* AsyncCmpStrm\<[GzipOptions](../interfaces/gzipoptions.md)>
+
+  ↳ **AsyncGzip**
+
+## Index
+
+### Constructors
+
+* [constructor](asyncgzip.md#constructor)
+
+### Properties
+
+* [ondata](asyncgzip.md#ondata)
+
+### Methods
+
+* [push](asyncgzip.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **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
+
+#### 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)
+
+*Inherited from [AsyncDeflate](asyncdeflate.md).[constructor](asyncdeflate.md#constructor)*
+
+*Overrides [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
+
+Creates an asynchronous compression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [AsyncGzip](asyncgzip.md)
+
+## Properties
+
+### ondata
+
+•  **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
+
+## Methods
+
+### push
+
+▸ **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:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 70 - 0
docs/classes/asyncinflate.md

@@ -0,0 +1,70 @@
+# Class: AsyncInflate
+
+Asynchronous streaming DEFLATE decompression
+
+## Hierarchy
+
+* AsyncStrm
+
+  ↳ **AsyncInflate**
+
+## Index
+
+### Constructors
+
+* [constructor](asyncinflate.md#constructor)
+
+### Properties
+
+* [ondata](asyncinflate.md#ondata)
+
+### Methods
+
+* [push](asyncinflate.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new AsyncInflate**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncInflate](asyncinflate.md)
+
+*Inherited from [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
+
+Creates an asynchronous decompression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is inflated  |
+
+**Returns:** [AsyncInflate](asyncinflate.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
+
+*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+*Inherited from [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
+
+Pushes a chunk to be inflated
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 70 - 0
docs/classes/asyncunzlib.md

@@ -0,0 +1,70 @@
+# Class: AsyncUnzlib
+
+Asynchronous streaming Zlib decompression
+
+## Hierarchy
+
+* AsyncStrm
+
+  ↳ **AsyncUnzlib**
+
+## Index
+
+### Constructors
+
+* [constructor](asyncunzlib.md#constructor)
+
+### Properties
+
+* [ondata](asyncunzlib.md#ondata)
+
+### Methods
+
+* [push](asyncunzlib.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new AsyncUnzlib**(`cb?`: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)): [AsyncUnzlib](asyncunzlib.md)
+
+*Inherited from [AsyncInflate](asyncinflate.md).[constructor](asyncinflate.md#constructor)*
+
+Creates an asynchronous decompression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is inflated  |
+
+**Returns:** [AsyncUnzlib](asyncunzlib.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
+
+*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+*Inherited from [AsyncInflate](asyncinflate.md).[push](asyncinflate.md#push)*
+
+Pushes a chunk to be inflated
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 91 - 0
docs/classes/asynczlib.md

@@ -0,0 +1,91 @@
+# Class: AsyncZlib
+
+Asynchronous streaming DEFLATE compression
+
+## Hierarchy
+
+* AsyncCmpStrm\<[ZlibOptions](../interfaces/zliboptions.md)>
+
+  ↳ **AsyncZlib**
+
+## Index
+
+### Constructors
+
+* [constructor](asynczlib.md#constructor)
+
+### Properties
+
+* [ondata](asynczlib.md#ondata)
+
+### Methods
+
+* [push](asynczlib.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **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
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [ZlibOptions](../interfaces/zliboptions.md) | The compression options |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [AsyncZlib](asynczlib.md)
+
+\+ **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
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [AsyncZlib](asynczlib.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [AsyncFlateStreamHandler](../README.md#asyncflatestreamhandler)
+
+*Inherited from [AsyncDeflate](asyncdeflate.md).[ondata](asyncdeflate.md#ondata)*
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **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:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 62 - 0
docs/classes/decompress.md

@@ -0,0 +1,62 @@
+# Class: Decompress
+
+Streaming GZIP, Zlib, or raw DEFLATE decompression
+
+## Hierarchy
+
+* **Decompress**
+
+## Index
+
+### Constructors
+
+* [constructor](decompress.md#constructor)
+
+### Properties
+
+* [ondata](decompress.md#ondata)
+
+### Methods
+
+* [push](decompress.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Decompress**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Decompress](decompress.md)
+
+Creates a decompression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is decompressed  |
+
+**Returns:** [Decompress](decompress.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be decompressed
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 75 - 0
docs/classes/deflate.md

@@ -0,0 +1,75 @@
+# Class: Deflate
+
+Streaming DEFLATE compression
+
+## Hierarchy
+
+* **Deflate**
+
+## Index
+
+### Constructors
+
+* [constructor](deflate.md#constructor)
+
+### Properties
+
+* [ondata](deflate.md#ondata)
+
+### Methods
+
+* [push](deflate.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Deflate**(`opts`: [DeflateOptions](../interfaces/deflateoptions.md), `cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Deflate](deflate.md)
+
+Creates a DEFLATE stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [DeflateOptions](../interfaces/deflateoptions.md) | The compression options |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Deflate](deflate.md)
+
+\+ **new Deflate**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Deflate](deflate.md)
+
+Creates a DEFLATE stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Deflate](deflate.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be deflated
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 62 - 0
docs/classes/gunzip.md

@@ -0,0 +1,62 @@
+# Class: Gunzip
+
+Streaming GZIP decompression
+
+## Hierarchy
+
+* **Gunzip**
+
+## Index
+
+### Constructors
+
+* [constructor](gunzip.md#constructor)
+
+### Properties
+
+* [ondata](gunzip.md#ondata)
+
+### Methods
+
+* [push](gunzip.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Gunzip**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Gunzip](gunzip.md)
+
+Creates a GUNZIP stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is inflated  |
+
+**Returns:** [Gunzip](gunzip.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be GUNZIPped
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 102 - 0
docs/classes/gzip.md

@@ -0,0 +1,102 @@
+# Class: Gzip
+
+Streaming GZIP compression
+Streaming GZIP compression
+
+## Hierarchy
+
+* **Gzip**
+
+## Index
+
+### Constructors
+
+* [constructor](gzip.md#constructor)
+
+### Properties
+
+* [ondata](gzip.md#ondata)
+
+### Methods
+
+* [push](gzip.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Gzip**(`opts`: [GzipOptions](../interfaces/gzipoptions.md), `cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Gzip](gzip.md)
+
+Creates a GZIP stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [GzipOptions](../interfaces/gzipoptions.md) | The compression options |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Gzip](gzip.md)
+
+\+ **new Gzip**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Gzip](gzip.md)
+
+Creates a GZIP stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Gzip](gzip.md)
+
+\+ **new Gzip**(`opts`: [GzipOptions](../interfaces/gzipoptions.md), `cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Gzip](gzip.md)
+
+Creates a GZIP stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [GzipOptions](../interfaces/gzipoptions.md) | The compression options |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Gzip](gzip.md)
+
+\+ **new Gzip**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Gzip](gzip.md)
+
+Creates a GZIP stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Gzip](gzip.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be GZIPped
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 62 - 0
docs/classes/inflate.md

@@ -0,0 +1,62 @@
+# Class: Inflate
+
+Streaming DEFLATE decompression
+
+## Hierarchy
+
+* **Inflate**
+
+## Index
+
+### Constructors
+
+* [constructor](inflate.md#constructor)
+
+### Properties
+
+* [ondata](inflate.md#ondata)
+
+### Methods
+
+* [push](inflate.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Inflate**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Inflate](inflate.md)
+
+Creates an inflation stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is inflated  |
+
+**Returns:** [Inflate](inflate.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be inflated
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the final chunk  |
+
+**Returns:** void

+ 62 - 0
docs/classes/unzlib.md

@@ -0,0 +1,62 @@
+# Class: Unzlib
+
+Streaming Zlib decompression
+
+## Hierarchy
+
+* **Unzlib**
+
+## Index
+
+### Constructors
+
+* [constructor](unzlib.md#constructor)
+
+### Properties
+
+* [ondata](unzlib.md#ondata)
+
+### Methods
+
+* [push](unzlib.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Unzlib**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Unzlib](unzlib.md)
+
+Creates a Zlib decompression stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is inflated  |
+
+**Returns:** [Unzlib](unzlib.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be unzlibbed
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 75 - 0
docs/classes/zlib.md

@@ -0,0 +1,75 @@
+# Class: Zlib
+
+Streaming Zlib compression
+
+## Hierarchy
+
+* **Zlib**
+
+## Index
+
+### Constructors
+
+* [constructor](zlib.md#constructor)
+
+### Properties
+
+* [ondata](zlib.md#ondata)
+
+### Methods
+
+* [push](zlib.md#push)
+
+## Constructors
+
+### constructor
+
+\+ **new Zlib**(`opts`: [ZlibOptions](../interfaces/zliboptions.md), `cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Zlib](zlib.md)
+
+Creates a Zlib stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`opts` | [ZlibOptions](../interfaces/zliboptions.md) | The compression options |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Zlib](zlib.md)
+
+\+ **new Zlib**(`cb?`: [FlateStreamHandler](../README.md#flatestreamhandler)): [Zlib](zlib.md)
+
+Creates a Zlib stream
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`cb?` | [FlateStreamHandler](../README.md#flatestreamhandler) | The callback to call whenever data is deflated  |
+
+**Returns:** [Zlib](zlib.md)
+
+## Properties
+
+### ondata
+
+•  **ondata**: [FlateStreamHandler](../README.md#flatestreamhandler)
+
+The handler to call whenever data is available
+
+## Methods
+
+### push
+
+▸ **push**(`chunk`: Uint8Array, `final?`: boolean): void
+
+Pushes a chunk to be zlibbed
+
+#### Parameters:
+
+Name | Type | Description |
+------ | ------ | ------ |
+`chunk` | Uint8Array | The chunk to push |
+`final?` | boolean | Whether this is the last chunk  |
+
+**Returns:** void

+ 7 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "fflate",
-  "version": "0.2.3",
+  "version": "0.3.0",
   "description": "High performance (de)compression in an 8kB package",
   "main": "lib/index.js",
   "module": "esm/index.js",
@@ -24,17 +24,21 @@
     "pako",
     "browser",
     "node.js",
-    "tiny"
+    "tiny",
+    "zip",
+    "unzip",
+    "non-blocking"
   ],
   "scripts": {
     "build": "yarn build:lib && yarn build:docs",
     "build:lib": "tsc && tsc --project tsconfig.esm.json",
-    "build:docs": "typedoc --mode library --plugin typedoc-plugin-markdown --hideProjectName --hideBreadcrumbs --readme none --disableSources src/index.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"
   },
   "devDependencies": {
     "@types/node": "^14.11.2",
+    "@types/pako": "*",
     "pako": "*",
     "tiny-inflate": "*",
     "ts-node": "^9.0.0",

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 281 - 162
src/index.ts


+ 12 - 12
src/node-worker.ts

@@ -1,20 +1,20 @@
 // Mediocre shim
-import { FlateCallback } from '.';
 import { Worker } from 'worker_threads';
-const workerAdd = ";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)};self=global";
-export default (c: string, msg: unknown, transfer: ArrayBuffer[], cb: FlateCallback) => {
+
+const workerAdd = ";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";
+
+export default <T>(c: string, _: number, msg: unknown, transfer: ArrayBuffer[], cb: (err: Error, msg: T) => void) => {
   let done = false;
-  const cb2: typeof cb = (e, d) => {
-    done = true;
-    wk.terminate();
-    cb(e, d);
-  }
   const wk = new Worker(c + workerAdd, { eval: true })
-    .on('error', e => cb2(e, null))
-    .on('message', m => cb2(null, m))
+    .on('error', e => cb(e, null))
+    .on('message', m => cb(null, m))
     .on('exit', c => {
-      if (!done) cb2(new Error('Exited with code ' + c), null);
+      if (c && !done) cb(new Error('Exited with code ' + c), null);
     });
   wk.postMessage(msg, transfer);
-  return () => { done = true; wk.terminate(); }
+  wk.terminate = () => {
+    done = true;
+    return Worker.prototype.terminate.call(wk);
+  }
+  return wk;
 }

+ 6 - 11
src/worker.ts

@@ -1,15 +1,10 @@
-import { FlateCallback } from '.';
+const ch: Record<string, string> = {};
 
-export default (c: string, msg: unknown, transfer: ArrayBuffer[], cb: FlateCallback) => {
-  const u = URL.createObjectURL(new Blob([c], { type: 'text/javascript' }));
+export default <T>(c: string, id: number, msg: unknown, transfer: ArrayBuffer[], cb: (err: Error, msg: T) => void) => {
+  const u = ch[id] ||= URL.createObjectURL(new Blob([c], { type: 'text/javascript' }));
   const w = new Worker(u);
-  const cb2: typeof cb = (e, d) => {
-    w.terminate();
-    URL.revokeObjectURL(u);
-    cb(e, d);
-  }
-  w.onerror = e => cb2(e.error, null);
-  w.onmessage = e => cb2(null, e.data);
+  w.onerror = e => cb(e.error, null);
+  w.onmessage = e => cb(null, e.data);
   w.postMessage(msg, transfer);
-  return () => w.terminate();
+  return w;
 }

+ 2 - 2
test/2-perf.ts

@@ -24,9 +24,9 @@ for (const k in workers) {
       const fileClone = bClone(file);
       let buf = fileClone;
       if (preprocessors[l]) {
-        buf = bClone(cache[l][name] || (cache[l][name] = Buffer.from(
+        buf = bClone(cache[l][name] ||= Buffer.from(
           await preprocessors[l as keyof typeof preprocessors](buf, [buf.buffer])
-        )));
+        ));
         resetTimer();
       }
       const opt2 = preprocessors[l]

+ 45 - 0
test/3-multiperf.ts

@@ -0,0 +1,45 @@
+import { testSuites } from './util';
+import { deflateSync, inflateSync } from '..';
+import { deflateRawSync, inflateRawSync } from 'zlib';
+import { deflateRaw, inflateRaw } from 'pako';
+import * as UZIP from 'uzip';
+import * as tinf from 'tiny-inflate';
+import { writeFileSync } from 'fs';
+import { join } from 'path';
+
+const cache: Record<string, Buffer> = {};
+
+testSuites({
+  'fflate compress 5x': file => {
+    for (let i = 0; i < 5; ++i) deflateSync(file);
+  },
+  'fflate decompress 5x': (file, name, resetTimer) => {
+    cache[name] = deflateRawSync(file), resetTimer();
+    for (let i = 0; i < 5; ++i) {
+      inflateSync(cache[name]);
+    }
+  },
+  'pako compress 5x': file => {
+    for (let i = 0; i < 5; ++i) deflateRaw(file);
+  },
+  'pako decompress 5x': (_, name) => {
+    for (let i = 0; i < 5; ++i) inflateRaw(cache[name]);
+  },
+  'uzip compress 5x': file => {
+    for (let i = 0; i < 5; ++i) UZIP.deflateRaw(file);
+  },
+  'uzip decompress 5x': (_, name) => {
+    for (let i = 0; i < 5; ++i) UZIP.inflateRaw(cache[name]);
+  },
+  'tiny-inflate decompress 5x': (file, name) => {
+    for (let i = 0; i < 5; ++i) tinf(cache[name], new Uint8Array(file.length));
+  },
+  'zlib compress 5x': file => {
+    for (let i = 0; i < 5; ++i) deflateRawSync(file);
+  },
+  'zlib decompress 5x': (_, name) => {
+    for (let i = 0; i < 5; ++i) inflateRawSync(cache[name]);
+  }
+}).then(perf => {
+  writeFileSync(join(__dirname, 'results', 'multiTimings.json'), JSON.stringify(perf, null, 2));
+})

+ 15 - 10
yarn.lock

@@ -12,6 +12,11 @@
   resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.2.tgz#2de1ed6670439387da1c9f549a2ade2b0a799256"
   integrity sha512-jiE3QIxJ8JLNcb1Ps6rDbysDhN4xa8DJJvuC9prr6w+1tIh+QAbYyNF3tyiZNLDBIuBCf4KEcV2UvQm/V60xfA==
 
+"@types/pako@*":
+  version "1.0.1"
+  resolved "https://registry.yarnpkg.com/@types/pako/-/pako-1.0.1.tgz#33b237f3c9aff44d0f82fe63acffa4a365ef4a61"
+  integrity sha512-GdZbRSJ3Cv5fiwT6I0SQ3ckeN2PWNqxd26W9Z2fCK1tGrrasGy4puvNFtnddqH9UJFMQYXxEuuB7B8UK+LLwSg==
+
 arg@^4.1.0:
   version "4.1.3"
   resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
@@ -47,10 +52,10 @@ [email protected]:
   resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
   integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
 
-dequal@^1.0.0, dequal@^2.0.2:
-  version "2.0.2"
-  resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.2.tgz#85ca22025e3a87e65ef75a7a437b35284a7e319d"
-  integrity sha512-q9K8BlJVxK7hQYqa6XISGmBZbtQQWVXSrRrWreHC94rMt1QL/Impruc+7p2CYSYuVIUr+YCt6hjrs1kkdJRTug==
+dequal@^1.0.0:
+  version "1.0.1"
+  resolved "https://registry.yarnpkg.com/dequal/-/dequal-1.0.1.tgz#dbbf9795ec626e9da8bd68782f4add1d23700d8b"
+  integrity sha512-Fx8jxibzkJX2aJgyfSdLhr9tlRoTnHKrRJuu2XHlAgKioN2j19/Bcbe0d4mFXYZ3+wpE2KVobUVTfDutcD17xQ==
 
 diff@^4.0.1, diff@^4.0.2:
   version "4.0.2"
@@ -189,7 +194,7 @@ once@^1.3.0:
   dependencies:
     wrappy "1"
 
-pako@^1.0.11:
+pako@*:
   version "1.0.11"
   resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
   integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
@@ -252,7 +257,7 @@ source-map@^0.6.0, source-map@^0.6.1:
   resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
   integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
 
-tiny-inflate@^1.0.3:
+tiny-inflate@*:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/tiny-inflate/-/tiny-inflate-1.0.3.tgz#122715494913a1805166aaf7c93467933eea26c4"
   integrity sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==
@@ -337,10 +342,10 @@ uvu@^0.3.3:
     sade "^1.7.3"
     totalist "^1.1.0"
 
-uzip@^0.20200919.0:
-  version "0.20200919.0"
-  resolved "https://registry.yarnpkg.com/uzip/-/uzip-0.20200919.0.tgz#a4ae1d13265f086021e2e7933412b9b8d9f06155"
-  integrity sha512-bdwScsEC5g17c7qZAHceJAm1TCuJl6f8JvpREkF2voFx00NlqU5yewvJrggXvIddEkxwyJ3e0DSrh6NDul/RHg==
+uzip@*:
+  version "0.20201014.0"
+  resolved "https://registry.yarnpkg.com/uzip/-/uzip-0.20201014.0.tgz#f95f27fe7a1d90e00b0aa392c785e6b4cbd75f7a"
+  integrity sha512-XQ/E2CeiMKqqT8LMq5yPCIgnbu/G1DvrcTrL6d1BtLas3l9TfAp+AqUr1tO6MyMCpDjB//0kDIJ9zW73sHyW5A==
 
 wordwrap@^1.0.0:
   version "1.0.0"

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است