Arjun Barrett преди 4 години
родител
ревизия
9ef7e32081
променени са 7 файла, в които са добавени 31 реда и са изтрити 33 реда
  1. 14 15
      README.md
  2. 7 7
      docs/README.md
  3. 2 2
      docs/interfaces/deflateoptions.md
  4. 4 4
      docs/interfaces/gzipoptions.md
  5. 2 2
      docs/interfaces/zliboptions.md
  6. 1 1
      package.json
  7. 1 2
      src/index.ts

+ 14 - 15
README.md

@@ -16,12 +16,8 @@ High performance (de)compression in an 8kB package
 ## Usage
 
 Install `fflate`:
-```console
-npm install --save fflate
-```
-or
-```console
-yarn add fflate
+```sh
+npm install --save fflate # or yarn add fflate, or pnpm add fflate
 ```
 
 Import:
@@ -31,7 +27,7 @@ import * as fflate from 'fflate';
 // So, if you just need gzip support:
 import { gzip, gunzip } from 'fflate';
 ```
-Or `require` (if your environment doesn't support ES Modules):
+If your environment doesn't support ES Modules (e.g. Node.js):
 ```js
 const fflate = require('fflate');
 ```
@@ -39,14 +35,17 @@ const fflate = require('fflate');
 And use:
 ```js
 // This is an ArrayBuffer of data
-const massiveFileBuf = await fetch('/getAMassiveFile').then(
+const massiveFileBuf = await fetch('/aMassiveFile').then(
   res => res.arrayBuffer()
 );
 // To use fflate, you need a Uint8Array
 const massiveFile = new Uint8Array(massiveFileBuf);
-// Note that the Node.js Buffer works just fine as well:
+// Note that Node.js Buffers work just fine as well:
 // const massiveFile = require('fs').readFileSync('aMassiveFile.txt');
 
+// Higher level means lower performance but better compression
+// The level ranges from 0 (no compression) to 9 (max compression)
+// The default level is 6
 const notSoMassive = fflate.zlib(massiveFile, { level: 9 });
 const massiveAgain = fflate.unzlib(notSoMassive);
 ```
@@ -55,7 +54,7 @@ const massiveAgain = fflate.unzlib(notSoMassive);
 const compressed = new Uint8Array(
   await fetch('/unknownFormatCompressedFile').then(res => res.arrayBuffer())
 );
-// Again, Node.js buffers work too. For example, the above could instead be:
+// Again, Node.js Buffers work too. For example, the above could instead be:
 // Buffer.from('H4sIAAAAAAAA//NIzcnJVyjPL8pJUQQAlRmFGwwAAAA=', 'base64');
 
 const decompressed = fflate.decompress(compressed);
@@ -65,8 +64,10 @@ Using strings is easy with `TextEncoder` and `TextDecoder`:
 ```js
 const enc = new TextEncoder(), dec = new TextDecoder();
 const buf = enc.encode('Hello world!');
+
 // The default compression method is gzip
-// See the docs for more info on the mem option
+// Increasing mem increases may increase performance at the cost of memory
+// The mem ranges from 0 to 12, where 4 is the default
 const compressed = fflate.compress(buf, { level: 6, mem: 8 });
 
 // When you need to decompress:
@@ -96,13 +97,11 @@ const decompressed = fflate.decompress(stringToCompressedData(compressedString))
 See the [documentation](https://github.com/101arrowz/fflate/blob/master/docs/README.md) for more detailed information about the API.
 
 ## What makes `fflate` so fast?
-There are many reasons one might need a compression/decompression library; for example, if a user is uploading a massive file (say a 50 MB PDF) to your server, instead of uploading directly, it's usually faster to compress the file before uploading. Or if you want to generate a ZIP file to download to your user's computer, you also may need to compress it.
-
-For these reasons (and many more) 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 badly written, `pako` doesn't recognize the many differences between JavaScript and C, and therefore is suboptimal. Moreover, even when minified, the library is 40 kB; it may not seem like much, but for anyone concerned with optimizing bundle size (especially library authors), it's more weight than necessary.
+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.
 
 Note that there exist some small libraries like [`tiny-inflate`](https://npmjs.com/package/tiny-inflate) for solely decompression, and with a minified size of 3 kB, it can be appealing; however, its performance is extremely lackluster, up to 100x slower than `pako` for some larger files in my tests.
 
-[`UZIP.js`](https://github.com/photopea/UZIP.js) is both faster (by up to 40%) and smaller (15 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`.
+[`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, 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.
 

+ 7 - 7
docs/README.md

@@ -24,7 +24,7 @@
 
 ▸ **decompress**(`data`: Uint8Array, `out?`: Uint8Array): Uint8Array
 
-*Defined in [index.ts:775](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L775)*
+*Defined in [index.ts:775](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L775)*
 
 Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
 
@@ -43,7 +43,7 @@ ___
 
 ▸ **deflate**(`data`: Uint8Array, `opts`: [DeflateOptions](interfaces/deflateoptions.md)): Uint8Array
 
-*Defined in [index.ts:681](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L681)*
+*Defined in [index.ts:681](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L681)*
 
 Compresses data with DEFLATE without any wrapper
 
@@ -62,7 +62,7 @@ ___
 
 ▸ **gunzip**(`data`: Uint8Array, `out?`: Uint8Array): Uint8Array
 
-*Defined in [index.ts:721](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L721)*
+*Defined in [index.ts:721](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L721)*
 
 Expands GZIP data
 
@@ -81,7 +81,7 @@ ___
 
 ▸ **gzip**(`data`: Uint8Array, `opts`: [GZIPOptions](interfaces/gzipoptions.md)): Uint8Array
 
-*Defined in [index.ts:701](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L701)*
+*Defined in [index.ts:701](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L701)*
 
 Compresses data with GZIP
 
@@ -100,7 +100,7 @@ ___
 
 ▸ **inflate**(`data`: Uint8Array, `out?`: Uint8Array): Uint8Array
 
-*Defined in [index.ts:691](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L691)*
+*Defined in [index.ts:691](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L691)*
 
 Expands DEFLATE data with no wrapper
 
@@ -119,7 +119,7 @@ ___
 
 ▸ **unzlib**(`data`: Uint8Array, `out?`: Uint8Array): Uint8Array
 
-*Defined in [index.ts:759](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L759)*
+*Defined in [index.ts:759](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L759)*
 
 Expands Zlib data
 
@@ -138,7 +138,7 @@ ___
 
 ▸ **zlib**(`data`: Uint8Array, `opts`: [ZlibOptions](interfaces/zliboptions.md)): Uint8Array
 
-*Defined in [index.ts:738](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L738)*
+*Defined in [index.ts:738](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L738)*
 
 Compress data with Zlib
 

+ 2 - 2
docs/interfaces/deflateoptions.md

@@ -23,7 +23,7 @@ Options for compressing data into a DEFLATE format
 
 • `Optional` **level**: 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8 \| 9
 
-*Defined in [index.ts:633](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L633)*
+*Defined in [index.ts:633](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L633)*
 
 The level of compression to use, ranging from 0-9.
 
@@ -45,7 +45,7 @@ ___
 
 • `Optional` **mem**: 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8 \| 9 \| 10 \| 11 \| 12
 
-*Defined in [index.ts:642](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L642)*
+*Defined in [index.ts:642](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L642)*
 
 The memory level to use, ranging from 0-12. Increasing this increases speed and compression ratio at the cost of memory.
 

+ 4 - 4
docs/interfaces/gzipoptions.md

@@ -23,7 +23,7 @@ Options for compressing data into a GZIP format
 
 • `Optional` **filename**: string
 
-*Defined in [index.ts:658](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L658)*
+*Defined in [index.ts:658](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L658)*
 
 The filename of the data. If the `gunzip` command is used to decompress the data, it will output a file
 with this name instead of the name of the compressed file.
@@ -36,7 +36,7 @@ ___
 
 *Inherited from [DeflateOptions](deflateoptions.md).[level](deflateoptions.md#level)*
 
-*Defined in [index.ts:633](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L633)*
+*Defined in [index.ts:633](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L633)*
 
 The level of compression to use, ranging from 0-9.
 
@@ -60,7 +60,7 @@ ___
 
 *Inherited from [DeflateOptions](deflateoptions.md).[mem](deflateoptions.md#mem)*
 
-*Defined in [index.ts:642](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L642)*
+*Defined in [index.ts:642](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L642)*
 
 The memory level to use, ranging from 0-12. Increasing this increases speed and compression ratio at the cost of memory.
 
@@ -75,7 +75,7 @@ ___
 
 • `Optional` **mtime**: Date \| string \| number
 
-*Defined in [index.ts:653](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L653)*
+*Defined in [index.ts:653](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L653)*
 
 When the file was last modified. Defaults to the current time.
 Set this to 0 to avoid specifying a modification date entirely.

+ 2 - 2
docs/interfaces/zliboptions.md

@@ -23,7 +23,7 @@ Options for compressing data into a Zlib format
 
 *Inherited from [DeflateOptions](deflateoptions.md).[level](deflateoptions.md#level)*
 
-*Defined in [index.ts:633](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L633)*
+*Defined in [index.ts:633](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L633)*
 
 The level of compression to use, ranging from 0-9.
 
@@ -47,7 +47,7 @@ ___
 
 *Inherited from [DeflateOptions](deflateoptions.md).[mem](deflateoptions.md#mem)*
 
-*Defined in [index.ts:642](https://github.com/101arrowz/fflate/blob/3362e39/src/index.ts#L642)*
+*Defined in [index.ts:642](https://github.com/101arrowz/fflate/blob/fcabaac/src/index.ts#L642)*
 
 The memory level to use, ranging from 0-12. Increasing this increases speed and compression ratio at the cost of memory.
 

+ 1 - 1
package.json

@@ -19,7 +19,7 @@
   ],
   "scripts": {
     "build": "tsc && tsc --project tsconfig.esm.json && typedoc --mode library --plugin typedoc-plugin-markdown --hideProjectName --hideBreadcrumbs --readme none",
-    "prepublish": "yarn build"
+    "prepare": "yarn build"
   },
   "devDependencies": {
     "pako": "^1.0.11",

+ 1 - 2
src/index.ts

@@ -39,8 +39,7 @@ const freb = (eb: Uint8Array, start: number) => {
 
 const [fl, revfl] = freb(fleb, 2);
 // we can ignore the fact that the other numbers are wrong; they never happen anyway
-fl[28] = 258;
-revfl[258] = 28;
+fl[28] = 258, revfl[258] = 28;
 const [fd, revfd] = freb(fdeb, 0);
 
 // map of value to reverse (assuming 16 bits)