README
@agen/gzip
This package contains methods providing async generators deflating / inflating (gzipping / gunzipping) binary input blocks:
- deflate method returns an async generator compressing ("deflating") input blocks
- inflate de-compresses ("inflates") binary blocks
This module uses the pako
package (the MIT license) to inflate/deflate streams:
https://github.com/nodeca/pako.
method inflate
This method decompress (inflates) binary data retunred by the input async
generators.
This method is based on the pako.Inflate
class.
Parameters:
options
- optional parameters (see thepako.Inflate
class)
Example: get binary data from the specified URL:
import { createReadStream } from 'fs';
import * as agen from '@agen/gzip';
const options = {}; // not required
const f = agen.inflate(options);
// Streams in NodeJS are also async generators providing binary blocks
const input = createReadStream('./myfile.gz');
for await (let chunk of f(input)) {
console.log('*', chunk);
}
method deflate
This method returns an async generator compressing (deflating) binary blocks comming from the input async generator (input stream).
This method is based on the pako.Deflate
class.
Parameters:
options
- optional parameters (see thepako.Deflate
class)
Example:
import { createReadStream } from 'fs';
import { deflate } from '@agen/gzip';
const options = {};
const f = agen.deflate(options);
// Streams in NodeJS are also async generators providing binary blocks
let input = createReadStream('./myfile.pdf');
for await (let chunk of f(input)) {
console.log('*', chunk);
}