import { ZStream } from './zstream.js'; import { GZheader } from './gzheader.js'; /** * class Deflate * * Generic JS-style wrapper for zlib calls. If you don't need * streaming behaviour - use more simple functions: [[deflate]], * [[deflateRaw]] and [[gzip]]. **/ /** * Deflate.result -> Uint8Array * * Compressed result, generated by default [[Deflate#onData]] * and [[Deflate#onEnd]] handlers. Filled after you push last chunk * (call [[Deflate#push]] with `Z_FINISH` / `true` param). **/ /** * Deflate.err -> Number * * Error code after deflate finished. 0 (Z_OK) on success. * You will not need it in real life, because deflate errors * are possible only on wrong options or bad `onData` / `onEnd` * custom handlers. **/ /** * Deflate.msg -> String * * Error message, if [[Deflate.err]] != 0 **/ type options = { level: number; windowBits: number; memLevel: number; strategy: number; dictionary: Uint8Array; chunkSize: number; raw: boolean; gzip: boolean; method: number; header: GZheader; to: string; }; type options_assigned = { level?: number; windowBits?: number; memLevel?: number; strategy?: number; dictionary?: Uint8Array; chunkSize?: number; raw?: boolean; gzip?: boolean; method?: number; header?: GZheader; to?: string; }; /** * new Deflate(options) * - options (Object): zlib deflate options. * * Creates new deflator instance with specified params. Throws exception * on bad params. Supported options: * * - `level` * - `windowBits` * - `memLevel` * - `strategy` * - `dictionary` * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) * for more information on these. * * Additional options, for internal needs: * * - `chunkSize` - size of generated data chunks (16K by default) * - `raw` (Boolean) - do raw deflate * - `gzip` (Boolean) - create gzip wrapper * - `header` (Object) - custom header for gzip * - `text` (Boolean) - true if compressed data believed to be text * - `time` (Number) - modification time, unix timestamp * - `os` (Number) - operation system code * - `extra` (Array) - array of bytes with extra data (max 65536) * - `name` (String) - file name (binary string) * - `comment` (String) - comment (binary string) * - `hcrc` (Boolean) - true if header crc should be added * * ##### Example: * * ```javascript * const zlib = require('deflate') * , chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9]) * , chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]); * * const deflate = new zlib.Deflate({ level: 3}); * * deflate.push(chunk1, false); * deflate.push(chunk2, true); // true -> last chunk * * if (deflate.err) { throw new Error(deflate.err); } * * console.log(deflate.result); * ``` * @param {options} options - options **/ export declare class Deflate { options: options; err: number; msg: string; ended: boolean | number; chunks: Uint8Array[]; strm: ZStream; _dict_set: boolean | undefined; result: Buffer | Uint8Array | undefined; constructor(options?: options_assigned); /** * Deflate#push(data[, flush_mode]) -> Boolean * - data (Uint8Array|ArrayBuffer|String): input data. Strings will be * converted to utf8 byte sequence. * - flush_mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH. * * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with * new compressed chunks. Returns `true` on success. The last data block must * have `flush_mode` Z_FINISH (or `true`). That will flush internal pending * buffers and call [[Deflate#onEnd]]. * * On fail call [[Deflate#onEnd]] with error code and return false. * * ##### Example * * ```javascript * push(chunk, false); // push one of data chunks * ... * push(chunk, true); // push last chunk * ``` * @param {Uint8Array|Buffer} data - source chunk * @param {boolean|number} flush_mode - `true` for finished **/ push(data: Uint8Array | Buffer, flush_mode: boolean | number): boolean; /** * Deflate#onData(chunk) -> Void * - chunk (Uint8Array): output data. * * By default, stores data blocks in `chunks[]` property and glue * those in `onEnd`. Override this handler, if you need another behaviour. * @param {Uint8Array|Buffer} chunk - source data **/ onData(chunk: Uint8Array | Buffer): void; /** * Deflate#onEnd(status) -> Void * - status (Number): deflate status. 0 (Z_OK) on success, * other if not. * * Called once after you tell deflate that the input stream is * complete (Z_FINISH). By default - join collected chunks, * free memory and fill `results` / `err` properties. **/ onEnd(status: number): void; } /** * deflate(data[, options]) -> Uint8Array * - data (Uint8Array|ArrayBuffer|String): input data to compress. * - options (Object): zlib deflate options. * * Compress `data` with deflate algorithm and `options`. * * Supported options are: * * - level * - windowBits * - memLevel * - strategy * - dictionary * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) * for more information on these. * * Sugar (options): * * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify * negative windowBits implicitly. * * ##### Example: * * ```javascript * const zlib = require('deflate') * const data = new Uint8Array([1,2,3,4,5,6,7,8,9]); * * console.log(zlib.deflate(data)); * ``` * @param {Buffer|Uint8Array} input - Input data * @param {options} options - options **/ export declare function deflate(input: Buffer | Uint8Array, options?: options_assigned): Uint8Array | Buffer | undefined; /** * deflateRaw(data[, options]) -> Uint8Array * - data (Uint8Array|ArrayBuffer|String): input data to compress. * - options (Object): zlib deflate options. * * The same as [[deflate]], but creates raw data, without wrapper * (header and adler32 crc). * @param {Buffer|Uint8Array} input - Input data * @param {options} options - options **/ export declare function deflateRaw(input: Buffer | Uint8Array, options?: options_assigned): Uint8Array | Buffer | undefined; /** * gzip(data[, options]) -> Uint8Array * - data (Uint8Array|ArrayBuffer|String): input data to compress. * - options (Object): zlib deflate options. * * The same as [[deflate]], but create gzip wrapper instead of * deflate one. * @param {Buffer|Uint8Array} input - Input data * @param {options} options - options **/ export declare function gzip(input: Buffer | Uint8Array, options?: options_assigned): Uint8Array | Buffer | undefined; /** * class Inflate * * Generic JS-style wrapper for zlib calls. If you don't need * streaming behaviour - use more simple functions: [[inflate]] * and [[inflateRaw]]. **/ /** * Inflate.result -> Uint8Array|String * * Uncompressed result, generated by default [[Inflate#onData]] * and [[Inflate#onEnd]] handlers. Filled after you push last chunk * (call [[Inflate#push]] with `Z_FINISH` / `true` param). **/ /** * Inflate.err -> Number * * Error code after inflate finished. 0 (Z_OK) on success. * Should be checked if broken data possible. **/ /** * Inflate.msg -> String * * Error message, if [[Inflate.err]] != 0 **/ /** * new Inflate(options) * - options (Object): zlib inflate options. * * Creates new inflator instance with specified params. Throws exception * on bad params. Supported options: * * - `windowBits` * - `dictionary` * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) * for more information on these. * * Additional options, for internal needs: * * - `chunkSize` - size of generated data chunks (16K by default) * - `raw` (Boolean) - do raw inflate * - `to` (String) - if equal to 'string', then result will be converted * from utf8 to utf16 (javascript) string. When string output requested, * chunk length can differ from `chunkSize`, depending on content. * * By default, when no options set, autodetect deflate/gzip data format via * wrapper header. * * ##### Example: * * ```javascript * const zlib = require('deflate') * const chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9]) * const chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]); * * const inflate = new zlib.Inflate({ level: 3}); * * inflate.push(chunk1, false); * inflate.push(chunk2, true); // true -> last chunk * * if (inflate.err) { throw new Error(inflate.err); } * * console.log(inflate.result); * ``` * @param {options} options - options **/ export declare class Inflate { options: options; err: number; msg: string; ended: boolean | number; chunks: Uint8Array[]; strm: ZStream; _dict_set: boolean | undefined; result: Buffer | Uint8Array | string | undefined; header: GZheader; constructor(options?: options_assigned); /** * Inflate#push(data[, flush_mode]) -> Boolean * - data (Uint8Array|ArrayBuffer): input data * - flush_mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE * flush modes. See constants. Skipped or `false` means Z_NO_FLUSH, * `true` means Z_FINISH. * * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with * new output chunks. Returns `true` on success. If end of stream detected, * [[Inflate#onEnd]] will be called. * * `flush_mode` is not needed for normal operation, because end of stream * detected automatically. You may try to use it for advanced things, but * this functionality was not tested. * * On fail call [[Inflate#onEnd]] with error code and return false. * * ##### Example * * ```javascript * push(chunk, false); // push one of data chunks * ... * push(chunk, true); // push last chunk * ``` * @param {Buffer|Uint8Array} data - input * @param {boolean} flush_mode - `true` for finished **/ push(data: Buffer | Uint8Array, flush_mode: number | boolean): boolean; /** * Inflate#onData(chunk) -> Void * - chunk (Uint8Array|String): output data. When string output requested, * each chunk will be string. * * By default, stores data blocks in `chunks[]` property and glue * those in `onEnd`. Override this handler, if you need another behaviour. **/ onData(chunk: Buffer | Uint8Array | string): void; /** * Inflate#onEnd(status) -> Void * - status (Number): inflate status. 0 (Z_OK) on success, * other if not. * * Called either after you tell inflate that the input stream is * complete (Z_FINISH). By default - join collected chunks, * free memory and fill `results` / `err` properties. **/ onEnd(status: number): void; } /** * inflate(data[, options]) -> Uint8Array|String * - data (Uint8Array|ArrayBuffer): input data to decompress. * - options (Object): zlib inflate options. * * Decompress `data` with inflate/ungzip and `options`. Autodetect * format via wrapper header by default. That's why we don't provide * separate `ungzip` method. * * Supported options are: * * - windowBits * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) * for more information. * * Sugar (options): * * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify * negative windowBits implicitly. * - `to` (String) - if equal to 'string', then result will be converted * from utf8 to utf16 (javascript) string. When string output requested, * chunk length can differ from `chunkSize`, depending on content. * * * ##### Example: * * ```javascript * const zlib = require('deflate'); * const input = zlib.deflate(new Uint8Array([1,2,3,4,5,6,7,8,9])); * let output; * * try { * output = zlib.inflate(input); * } catch (err) { * console.log(err); * } * ``` **/ export declare function inflate(input: Buffer | Uint8Array | string, options?: options_assigned): string | Uint8Array | Buffer | undefined; /** * inflateRaw(data[, options]) -> Uint8Array|String * - data (Uint8Array|ArrayBuffer): input data to decompress. * - options (Object): zlib inflate options. * * The same as [[inflate]], but creates raw data, without wrapper * (header and adler32 crc). **/ export declare function inflateRaw(input: Buffer | Uint8Array | string, options?: options_assigned): string | Uint8Array | Buffer | undefined; /** * ungzip(data[, options]) -> Uint8Array|String * - data (Uint8Array|ArrayBuffer): input data to decompress. * - options (Object): zlib inflate options. * * Just shortcut to [[inflate]], because it autodetects format * by header.content. Done for convenience. **/ export declare function ungzip(input: Buffer | Uint8Array | string, options?: options_assigned): string | Uint8Array | Buffer | undefined; export {}; //# sourceMappingURL=index.d.ts.map