[6a3a178] | 1 | # minizlib
|
---|
| 2 |
|
---|
| 3 | A fast zlib stream built on [minipass](http://npm.im/minipass) and
|
---|
| 4 | Node.js's zlib binding.
|
---|
| 5 |
|
---|
| 6 | This module was created to serve the needs of
|
---|
| 7 | [node-tar](http://npm.im/tar) and
|
---|
| 8 | [minipass-fetch](http://npm.im/minipass-fetch).
|
---|
| 9 |
|
---|
| 10 | Brotli is supported in versions of node with a Brotli binding.
|
---|
| 11 |
|
---|
| 12 | ## How does this differ from the streams in `require('zlib')`?
|
---|
| 13 |
|
---|
| 14 | First, there are no convenience methods to compress or decompress a
|
---|
| 15 | buffer. If you want those, use the built-in `zlib` module. This is
|
---|
| 16 | only streams. That being said, Minipass streams to make it fairly easy to
|
---|
| 17 | use as one-liners: `new zlib.Deflate().end(data).read()` will return the
|
---|
| 18 | deflate compressed result.
|
---|
| 19 |
|
---|
| 20 | This module compresses and decompresses the data as fast as you feed
|
---|
| 21 | it in. It is synchronous, and runs on the main process thread. Zlib
|
---|
| 22 | and Brotli operations can be high CPU, but they're very fast, and doing it
|
---|
| 23 | this way means much less bookkeeping and artificial deferral.
|
---|
| 24 |
|
---|
| 25 | Node's built in zlib streams are built on top of `stream.Transform`.
|
---|
| 26 | They do the maximally safe thing with respect to consistent
|
---|
| 27 | asynchrony, buffering, and backpressure.
|
---|
| 28 |
|
---|
| 29 | See [Minipass](http://npm.im/minipass) for more on the differences between
|
---|
| 30 | Node.js core streams and Minipass streams, and the convenience methods
|
---|
| 31 | provided by that class.
|
---|
| 32 |
|
---|
| 33 | ## Classes
|
---|
| 34 |
|
---|
| 35 | - Deflate
|
---|
| 36 | - Inflate
|
---|
| 37 | - Gzip
|
---|
| 38 | - Gunzip
|
---|
| 39 | - DeflateRaw
|
---|
| 40 | - InflateRaw
|
---|
| 41 | - Unzip
|
---|
| 42 | - BrotliCompress (Node v10 and higher)
|
---|
| 43 | - BrotliDecompress (Node v10 and higher)
|
---|
| 44 |
|
---|
| 45 | ## USAGE
|
---|
| 46 |
|
---|
| 47 | ```js
|
---|
| 48 | const zlib = require('minizlib')
|
---|
| 49 | const input = sourceOfCompressedData()
|
---|
| 50 | const decode = new zlib.BrotliDecompress()
|
---|
| 51 | const output = whereToWriteTheDecodedData()
|
---|
| 52 | input.pipe(decode).pipe(output)
|
---|
| 53 | ```
|
---|
| 54 |
|
---|
| 55 | ## REPRODUCIBLE BUILDS
|
---|
| 56 |
|
---|
| 57 | To create reproducible gzip compressed files across different operating
|
---|
| 58 | systems, set `portable: true` in the options. This causes minizlib to set
|
---|
| 59 | the `OS` indicator in byte 9 of the extended gzip header to `0xFF` for
|
---|
| 60 | 'unknown'.
|
---|