Add existing to tracked
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (C) 2014-2017 by Vitaly Puzrin and Andrei Tuputcyn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
pako
|
||||
==========================================
|
||||
|
||||
[](https://github.com/nodeca/pako/actions)
|
||||
[](https://www.npmjs.org/package/pako)
|
||||
|
||||
> Very fast zlib-compatible compression for JavaScript.
|
||||
|
||||
## Why pako is cool
|
||||
|
||||
- __Binary-equivalent output.__ Pako can produce the same deflate/gzip bytes as
|
||||
original [zlib](http://www.zlib.net/) (1.3.2) and Node.js' patched zlib.
|
||||
- __Tiny browser bundles.__ Full minified bundle is under 15K gzipped.
|
||||
Deflate-only and inflate-only builds are smaller.
|
||||
- __Very fast.__ Performance is comparable with native zlib in modern JavaScript
|
||||
engines (see benchmarks).
|
||||
|
||||
|
||||
## Benchmarks
|
||||
|
||||
node v24, 1 MB input sample:
|
||||
|
||||
```
|
||||
deflate-pako x 14.27 ops/sec ±3.41% (37 runs sampled)
|
||||
deflate-pako-zlib-hash x 10.60 ops/sec ±0.50% (29 runs sampled)
|
||||
deflate-zlib x 30.30 ops/sec ±0.61% (51 runs sampled)
|
||||
gzip-pako x 13.48 ops/sec ±0.50% (36 runs sampled)
|
||||
inflate-pako x 138 ops/sec ±1.26% (75 runs sampled)
|
||||
inflate-zlib x 397 ops/sec ±1.37% (81 runs sampled)
|
||||
ungzip-pako x 125 ops/sec ±1.46% (73 runs sampled)
|
||||
```
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install pako
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> For a quick look at `dist/` folder contents, see
|
||||
> <https://unpkg.com/pako@latest/>.
|
||||
|
||||
|
||||
Examples / API
|
||||
--------------
|
||||
|
||||
Full docs - http://nodeca.github.io/pako/
|
||||
|
||||
```javascript
|
||||
import { Deflate, Inflate, deflate, inflate } from 'pako';
|
||||
|
||||
// Deflate
|
||||
//
|
||||
const input = new Uint8Array();
|
||||
//... fill input data here
|
||||
const output = deflate(input);
|
||||
|
||||
// Inflate (simple wrapper can throw exception on broken stream)
|
||||
//
|
||||
const compressed = new Uint8Array();
|
||||
//... fill data to uncompress here
|
||||
try {
|
||||
const result = inflate(compressed);
|
||||
// ... continue processing
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
//
|
||||
// Alternate interface for chunking & without exceptions
|
||||
//
|
||||
|
||||
const deflator = new Deflate();
|
||||
|
||||
deflator.push(chunk1, false);
|
||||
deflator.push(chunk2); // second param is false by default.
|
||||
...
|
||||
deflator.push(chunk_last, true); // `true` says this chunk is last
|
||||
|
||||
if (deflator.err) {
|
||||
console.log(deflator.msg);
|
||||
}
|
||||
|
||||
const output = deflator.result;
|
||||
|
||||
|
||||
const inflator = new Inflate();
|
||||
|
||||
inflator.push(chunk1);
|
||||
inflator.push(chunk2);
|
||||
...
|
||||
inflator.push(chunk_last); // no second param because end is auto-detected
|
||||
|
||||
if (inflator.err) {
|
||||
console.log(inflator.msg);
|
||||
}
|
||||
|
||||
const output = inflator.result;
|
||||
```
|
||||
|
||||
For CommonJS:
|
||||
|
||||
```javascript
|
||||
const { deflate, inflate } = require('pako');
|
||||
```
|
||||
|
||||
If you need the whole API as an object, use namespace import:
|
||||
|
||||
```javascript
|
||||
import * as pako from 'pako';
|
||||
```
|
||||
|
||||
Sometimes you may wish to work with strings — for example, to send
|
||||
stringified objects to a server. Pako's deflate detects the input data type and
|
||||
automatically recodes strings to utf-8 prior to compression. High-level inflate
|
||||
helpers can decode utf-8 output back to JavaScript strings with `toText: true`.
|
||||
|
||||
```javascript
|
||||
import { deflate, inflate } from 'pako';
|
||||
|
||||
const test = { my: 'super', puper: [456, 567], awesome: 'pako' };
|
||||
|
||||
const compressed = deflate(JSON.stringify(test));
|
||||
|
||||
const restored = JSON.parse(inflate(compressed, { toText: true }));
|
||||
```
|
||||
|
||||
|
||||
## Notes
|
||||
|
||||
Pako does not contain some specific zlib functions:
|
||||
|
||||
- __deflate__ - methods `deflateCopy`, `deflateBound`, `deflateParams`,
|
||||
`deflatePending`, `deflatePrime`, `deflateTune`.
|
||||
- __inflate__ - methods `inflateCopy`, `inflateMark`,
|
||||
`inflatePrime`, `inflateGetDictionary`, `inflateSync`, `inflateSyncPoint`, `inflateUndermine`.
|
||||
- High level inflate/deflate wrappers (classes) may not support some flush
|
||||
modes.
|
||||
|
||||
|
||||
## Authors
|
||||
|
||||
- Andrey Tupitsin [@anrd83](https://github.com/andr83)
|
||||
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
|
||||
|
||||
Personal thanks to:
|
||||
|
||||
- Vyacheslav Egorov ([@mraleph](https://github.com/mraleph)) for his awesome
|
||||
tutorials about optimising JS code for v8, [IRHydra](http://mrale.ph/irhydra/)
|
||||
tool and his advices.
|
||||
- David Duponchel ([@dduponchel](https://github.com/dduponchel)) for help with
|
||||
testing.
|
||||
|
||||
Original implementation (in C):
|
||||
|
||||
- [zlib](http://zlib.net/) by Jean-loup Gailly and Mark Adler.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
- MIT - all files, except `/src/zlib` folder
|
||||
- ZLIB - `/src/zlib` content
|
||||
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+3744
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
+489
@@ -0,0 +1,489 @@
|
||||
/** @category constants */
|
||||
type Z_FlushMode =
|
||||
| typeof Z_NO_FLUSH
|
||||
| typeof Z_PARTIAL_FLUSH
|
||||
| typeof Z_SYNC_FLUSH
|
||||
| typeof Z_FULL_FLUSH
|
||||
| typeof Z_FINISH
|
||||
| typeof Z_BLOCK
|
||||
| typeof Z_TREES;
|
||||
|
||||
/** @category constants */
|
||||
type Z_CallStatus =
|
||||
| typeof Z_OK
|
||||
| typeof Z_STREAM_END
|
||||
| typeof Z_NEED_DICT
|
||||
| typeof Z_ERRNO
|
||||
| typeof Z_STREAM_ERROR
|
||||
| typeof Z_DATA_ERROR
|
||||
| typeof Z_MEM_ERROR
|
||||
| typeof Z_BUF_ERROR;
|
||||
|
||||
/** @category zlib */
|
||||
declare class ZStream {
|
||||
input: Uint8Array;
|
||||
next_in: number;
|
||||
avail_in: number;
|
||||
total_in: number;
|
||||
output: Uint8Array<ArrayBuffer>;
|
||||
next_out: number;
|
||||
avail_out: number;
|
||||
total_out: number;
|
||||
msg: string;
|
||||
state: any;
|
||||
data_type: number;
|
||||
adler: number;
|
||||
}
|
||||
|
||||
/** @category zlib */
|
||||
declare class GZheader {
|
||||
text: number;
|
||||
time: number;
|
||||
xflags: number;
|
||||
os: number;
|
||||
extra: Uint8Array | number[] | null;
|
||||
extra_len: number;
|
||||
name: string | null;
|
||||
comment: string | null;
|
||||
hcrc: boolean;
|
||||
done: boolean;
|
||||
}
|
||||
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateInit(strm: ZStream, level: number): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateInit2(
|
||||
strm: ZStream,
|
||||
level: number,
|
||||
method: number,
|
||||
windowBits: number,
|
||||
memLevel: number,
|
||||
strategy: number,
|
||||
legacyHash?: boolean
|
||||
): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateReset(strm: ZStream): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateResetKeep(strm: ZStream): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateSetHeader(strm: ZStream, head: GZheader): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateSetDictionary(strm: ZStream, dictionary: Uint8Array): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflate(strm: ZStream, flush: Z_FlushMode): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibDeflateEnd(strm: ZStream): Z_CallStatus;
|
||||
|
||||
/** @category zlib */
|
||||
declare function zlibInflateReset(strm: ZStream): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateReset2(strm: ZStream, windowBits: number): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateResetKeep(strm: ZStream): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateInit(strm: ZStream): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateInit2(strm: ZStream, windowBits: number): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateGetHeader(strm: ZStream, head: GZheader): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateSetDictionary(strm: ZStream, dictionary: Uint8Array): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflate(strm: ZStream, flush: Z_FlushMode): Z_CallStatus;
|
||||
/** @category zlib */
|
||||
declare function zlibInflateEnd(strm: ZStream): Z_CallStatus;
|
||||
|
||||
/** @category constants */
|
||||
declare const Z_NO_FLUSH: 0;
|
||||
/** @category constants */
|
||||
declare const Z_PARTIAL_FLUSH: 1;
|
||||
/** @category constants */
|
||||
declare const Z_SYNC_FLUSH: 2;
|
||||
/** @category constants */
|
||||
declare const Z_FULL_FLUSH: 3;
|
||||
/** @category constants */
|
||||
declare const Z_FINISH: 4;
|
||||
/** @category constants */
|
||||
declare const Z_BLOCK: 5;
|
||||
/** @category constants */
|
||||
declare const Z_TREES: 6;
|
||||
|
||||
/** @category constants */
|
||||
declare const Z_OK: 0;
|
||||
/** @category constants */
|
||||
declare const Z_STREAM_END: 1;
|
||||
/** @category constants */
|
||||
declare const Z_NEED_DICT: 2;
|
||||
/** @category constants */
|
||||
declare const Z_ERRNO: -1;
|
||||
/** @category constants */
|
||||
declare const Z_STREAM_ERROR: -2;
|
||||
/** @category constants */
|
||||
declare const Z_DATA_ERROR: -3;
|
||||
/** @category constants */
|
||||
declare const Z_MEM_ERROR: -4;
|
||||
/** @category constants */
|
||||
declare const Z_BUF_ERROR: -5;
|
||||
|
||||
/** @inline */
|
||||
type DeflateInput = Uint8Array | ArrayBuffer | string;
|
||||
interface DeflateOptions {
|
||||
/**
|
||||
* Compression level. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
level?: number;
|
||||
/**
|
||||
* Size of generated data chunks (16K by default).
|
||||
* @group Extensions
|
||||
*/
|
||||
chunkSize?: number;
|
||||
/**
|
||||
* Window size. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
windowBits?: number;
|
||||
/**
|
||||
* Memory level. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
memLevel?: number;
|
||||
/**
|
||||
* Compression strategy. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
strategy?: number;
|
||||
/**
|
||||
* Do raw deflate. Say that we work with raw stream, if you don't wish to
|
||||
* specify negative `windowBits` implicitly.
|
||||
* @group Extensions
|
||||
*/
|
||||
raw?: boolean;
|
||||
/**
|
||||
* Create gzip wrapper.
|
||||
* @group Extensions
|
||||
*/
|
||||
gzip?: boolean;
|
||||
/**
|
||||
* Initial dictionary. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
dictionary?: Uint8Array | ArrayBuffer;
|
||||
/**
|
||||
* Set to `true` to use the classic zlib hash, which matches canonical zlib
|
||||
* output byte-for-byte. The default `false` uses the faster ANZAC++ hash,
|
||||
* which matches recent (chromium) node.js output instead.
|
||||
* @group Extensions
|
||||
*/
|
||||
legacyHash?: boolean;
|
||||
}
|
||||
/**
|
||||
* Generic JS-style wrapper for zlib calls. If you don't need
|
||||
* streaming behaviour, use the simpler functions {@link deflate},
|
||||
* {@link deflateRaw} and {@link gzip}.
|
||||
*/
|
||||
declare class Deflate {
|
||||
private options;
|
||||
/**
|
||||
* Error code after deflate finishes. {@link Z_OK} on success.
|
||||
* You will not need it in real life, because deflate errors
|
||||
* are possible only on wrong options or bad custom `onData` / `onEnd`
|
||||
* handlers.
|
||||
*/
|
||||
err: Z_CallStatus;
|
||||
/** Error message, if {@link Deflate.err} is not {@link Z_OK}. */
|
||||
msg: string;
|
||||
private ended;
|
||||
private started;
|
||||
/**
|
||||
* Chunks of output data, if {@link Deflate.onData} not overridden.
|
||||
* @internal
|
||||
*/
|
||||
chunks: Uint8Array<ArrayBuffer>[];
|
||||
private strm;
|
||||
/**
|
||||
* Compressed result, generated by default {@link Deflate.onData}
|
||||
* and {@link Deflate.onEnd} handlers. Filled after you push last chunk
|
||||
* (call {@link Deflate.push} with {@link Z_FINISH} / `true` param).
|
||||
*/
|
||||
result: Uint8Array<ArrayBuffer>;
|
||||
/**
|
||||
* Creates a new deflator instance with the specified params. Throws an
|
||||
* exception on bad params. See {@link DeflateOptions} for the list of
|
||||
* supported options.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* import { Deflate } from 'pako'
|
||||
*
|
||||
* 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 deflate = new 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)
|
||||
* ```
|
||||
*/
|
||||
constructor(options?: DeflateOptions);
|
||||
/**
|
||||
* Sends input data to the deflate pipe, generating {@link Deflate.onData} calls
|
||||
* with new compressed chunks. Returns `true` on success. The last data block must
|
||||
* have `flush_mode` {@link Z_FINISH} (or `true`). That will flush the internal
|
||||
* pending buffers and call {@link Deflate.onEnd}.
|
||||
*
|
||||
* On failure, calls {@link Deflate.onEnd} with the error code and returns false.
|
||||
*
|
||||
* @param data input data. Strings will be converted to utf8 byte sequence.
|
||||
* @param flush_mode 0..6 for corresponding {@link Z_NO_FLUSH}..{@link Z_TREES} modes.
|
||||
* See constants. Skipped or `false` means {@link Z_NO_FLUSH}, `true` means {@link Z_FINISH}.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* push(chunk, false) // push one of data chunks
|
||||
* ...
|
||||
* push(chunk, true) // push last chunk
|
||||
* ```
|
||||
*/
|
||||
push(data: DeflateInput, flush_mode?: Z_FlushMode | boolean): boolean;
|
||||
/**
|
||||
* Called once before the first low-level deflate call.
|
||||
*/
|
||||
onStart(strm: ZStream): void;
|
||||
/**
|
||||
* By default, stores data blocks in the {@link Deflate.chunks} property and glues
|
||||
* them in {@link Deflate.onEnd}. Override this handler if you need another behaviour.
|
||||
*/
|
||||
onData(chunk: Uint8Array<ArrayBuffer>): void;
|
||||
/**
|
||||
* Called once after you tell deflate that the input stream is
|
||||
* complete ({@link Z_FINISH}). By default, joins the collected {@link Deflate.chunks}
|
||||
* into the {@link Deflate.result} property.
|
||||
*
|
||||
* @param status deflate status. {@link Z_OK} on success, other if not.
|
||||
*/
|
||||
onEnd(status: Z_CallStatus): void;
|
||||
}
|
||||
/**
|
||||
* Compress `data` with deflate algorithm and `options`.
|
||||
* See {@link DeflateOptions} for the list of supported options.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* import { deflate } from 'pako'
|
||||
*
|
||||
* const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])
|
||||
*
|
||||
* console.log(deflate(data))
|
||||
* ```
|
||||
*/
|
||||
declare function deflate(input: DeflateInput, options?: DeflateOptions): Uint8Array<ArrayBuffer>;
|
||||
/**
|
||||
* The same as {@link deflate}, but creates raw data without a wrapper
|
||||
* (header and adler32 crc).
|
||||
*/
|
||||
declare function deflateRaw(input: DeflateInput, options?: DeflateOptions): Uint8Array<ArrayBuffer>;
|
||||
/**
|
||||
* The same as {@link deflate}, but creates a gzip wrapper instead of
|
||||
* a deflate one.
|
||||
*/
|
||||
declare function gzip(input: DeflateInput, options?: DeflateOptions): Uint8Array<ArrayBuffer>;
|
||||
|
||||
/** @inline */
|
||||
type InflateInput = Uint8Array | ArrayBuffer;
|
||||
interface InflateOptions {
|
||||
/**
|
||||
* Window size. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
windowBits?: number;
|
||||
/**
|
||||
* Initial dictionary. See the
|
||||
* [zlib manual](http://zlib.net/manual.html#Advanced) for more information.
|
||||
* @group zlib options
|
||||
*/
|
||||
dictionary?: Uint8Array | ArrayBuffer;
|
||||
/**
|
||||
* Size of generated data chunks (64K by default).
|
||||
* @group Extensions
|
||||
*/
|
||||
chunkSize?: number;
|
||||
/**
|
||||
* Do raw inflate. Say that we work with raw stream, if you don't wish to
|
||||
* specify negative `windowBits` implicitly.
|
||||
* @group Extensions
|
||||
*/
|
||||
raw?: boolean;
|
||||
}
|
||||
/**
|
||||
* Generic JS-style wrapper for zlib calls. If you don't need
|
||||
* streaming behaviour, use the simpler functions {@link inflate}
|
||||
* and {@link inflateRaw}.
|
||||
*/
|
||||
declare class Inflate {
|
||||
private options;
|
||||
/**
|
||||
* Error code after inflate finishes. {@link Z_OK} on success.
|
||||
* Should be checked when broken data is possible.
|
||||
*/
|
||||
err: Z_CallStatus;
|
||||
/** Error message, if {@link Inflate.err} is not {@link Z_OK}. */
|
||||
msg: string;
|
||||
/**
|
||||
* `true` once the compressed stream has ended. A stream may end before the
|
||||
* caller's data does (trailing bytes), so check this to know when to stop
|
||||
* pushing - further {@link Inflate.push} calls are no-ops.
|
||||
*/
|
||||
ended: boolean;
|
||||
private started;
|
||||
/**
|
||||
* Chunks of output data, if {@link Inflate.onData} not overridden.
|
||||
* @internal
|
||||
*/
|
||||
chunks: Uint8Array<ArrayBuffer>[];
|
||||
private strm;
|
||||
/**
|
||||
* Uncompressed result, generated by default {@link Inflate.onData}
|
||||
* and {@link Inflate.onEnd} handlers. Filled after you push last chunk
|
||||
* (call {@link Inflate.push} with {@link Z_FINISH} / `true` param).
|
||||
*/
|
||||
result: Uint8Array<ArrayBuffer>;
|
||||
/**
|
||||
* Creates a new inflator instance with the specified params. Throws an
|
||||
* exception on bad params. See {@link InflateOptions} for the list of
|
||||
* supported options.
|
||||
*
|
||||
* By default, when no options are set, the deflate/gzip data format is
|
||||
* autodetected via the wrapper header.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* import { Inflate } from 'pako'
|
||||
*
|
||||
* 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 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)
|
||||
* ```
|
||||
*/
|
||||
constructor(options?: InflateOptions);
|
||||
/**
|
||||
* Sends input data to the inflate pipe, generating {@link Inflate.onData} calls
|
||||
* with new output chunks. Returns `true` on success. If end of stream is
|
||||
* detected, {@link Inflate.onEnd} will be called.
|
||||
*
|
||||
* `flush_mode` is not needed for normal operation, because end of stream
|
||||
* is detected automatically. Pass {@link Z_SYNC_FLUSH} to force the decoder
|
||||
* to emit all currently available output — handy when you need to decode
|
||||
* data frame-by-frame from a long-running stream.
|
||||
*
|
||||
* On failure, calls {@link Inflate.onEnd} with the error code and returns false.
|
||||
*
|
||||
* Once the stream has ended (a compressed stream may end before your data
|
||||
* does), further `push` calls are no-ops and return whether the decode
|
||||
* finished successfully. The final outcome is in {@link Inflate.result},
|
||||
* {@link Inflate.err} and {@link Inflate.msg}.
|
||||
*
|
||||
* @param flush_mode 0..6 for corresponding {@link Z_NO_FLUSH}..{@link Z_TREES}
|
||||
* flush modes. See constants. Skipped or `false` means {@link Z_NO_FLUSH},
|
||||
* `true` means {@link Z_FINISH}.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* push(chunk, false) // push one of data chunks
|
||||
* ...
|
||||
* push(chunk, true) // push last chunk
|
||||
* ```
|
||||
*/
|
||||
push(data: InflateInput, flush_mode?: Z_FlushMode | boolean): boolean;
|
||||
/**
|
||||
* Called once before the first low-level inflate call.
|
||||
*
|
||||
* Override this handler to attach low-level inflate state, for example to read
|
||||
* gzip header metadata:
|
||||
*
|
||||
* ```javascript
|
||||
* import { Inflate, GZheader, zlibInflateGetHeader } from 'pako'
|
||||
*
|
||||
* const inflator = new Inflate()
|
||||
*
|
||||
* inflator.onStart = function (strm) {
|
||||
* this.header = new GZheader()
|
||||
* zlibInflateGetHeader(strm, this.header)
|
||||
* }
|
||||
*
|
||||
* inflator.push(data, true)
|
||||
* console.log(inflator.header.name)
|
||||
* ```
|
||||
*/
|
||||
onStart(strm: ZStream): void;
|
||||
/**
|
||||
* By default, stores data blocks in the {@link Inflate.chunks} property and glues
|
||||
* them in {@link Inflate.onEnd}. Override this handler if you need another behaviour.
|
||||
*
|
||||
* @param chunk output data.
|
||||
*/
|
||||
onData(chunk: Uint8Array<ArrayBuffer>): void;
|
||||
/**
|
||||
* Called after you tell inflate that the input stream is
|
||||
* complete ({@link Z_FINISH}). By default, joins the collected {@link Inflate.chunks},
|
||||
* frees memory and fills the {@link Inflate.result} property.
|
||||
*
|
||||
* @param status inflate status. {@link Z_OK} on success, other if not.
|
||||
*/
|
||||
onEnd(status: Z_CallStatus): void;
|
||||
}
|
||||
/**
|
||||
* One-shot inflate decompress. Autodetects `gzip`/`zlib`
|
||||
* format via the wrapper header — so {@link ungzip} is just a convenience alias of
|
||||
* this function. See {@link InflateOptions} for zlib options. Set
|
||||
* `toText: true` to decode the result as UTF-8 text.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* import { deflate, inflate } from 'pako'
|
||||
*
|
||||
* const input = deflate(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]))
|
||||
* let output
|
||||
*
|
||||
* try {
|
||||
* output = inflate(input)
|
||||
* } catch (err) {
|
||||
* console.log(err)
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
declare function inflate<O extends InflateOptions & {
|
||||
toText?: boolean;
|
||||
}>(input: InflateInput, options?: O): O extends {
|
||||
toText: true;
|
||||
} ? string : Uint8Array<ArrayBuffer>;
|
||||
/**
|
||||
* The same as {@link inflate}, but consumes raw data without a wrapper
|
||||
* (header and adler32 crc).
|
||||
*/
|
||||
declare function inflateRaw<O extends InflateOptions & {
|
||||
toText?: boolean;
|
||||
}>(input: InflateInput, options?: O): O extends {
|
||||
toText: true;
|
||||
} ? string : Uint8Array<ArrayBuffer>;
|
||||
|
||||
export { Deflate, GZheader, Inflate, ZStream, Z_BLOCK, Z_BUF_ERROR, Z_DATA_ERROR, Z_ERRNO, Z_FINISH, Z_FULL_FLUSH, Z_MEM_ERROR, Z_NEED_DICT, Z_NO_FLUSH, Z_OK, Z_PARTIAL_FLUSH, Z_STREAM_END, Z_STREAM_ERROR, Z_SYNC_FLUSH, Z_TREES, deflate, deflateRaw, gzip, inflate, inflateRaw, inflate as ungzip, zlibDeflate, zlibDeflateEnd, zlibDeflateInit, zlibDeflateInit2, zlibDeflateReset, zlibDeflateResetKeep, zlibDeflateSetDictionary, zlibDeflateSetHeader, zlibInflate, zlibInflateEnd, zlibInflateGetHeader, zlibInflateInit, zlibInflateInit2, zlibInflateReset, zlibInflateReset2, zlibInflateResetKeep, zlibInflateSetDictionary };
|
||||
export type { DeflateOptions, InflateOptions, Z_CallStatus, Z_FlushMode };
|
||||
+3608
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
+86
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"name": "pako",
|
||||
"description": "zlib port to javascript - fast, modularized, with browser support",
|
||||
"version": "3.0.1",
|
||||
"keywords": [
|
||||
"zlib",
|
||||
"deflate",
|
||||
"inflate",
|
||||
"gzip"
|
||||
],
|
||||
"contributors": [
|
||||
"Andrei Tuputcyn (https://github.com/andr83)",
|
||||
"Vitaly Puzrin (https://github.com/puzrin)",
|
||||
"Friedel Ziegelmayer (https://github.com/dignifiedquire)",
|
||||
"Kirill Efimov (https://github.com/Kirill89)",
|
||||
"Jean-loup Gailly",
|
||||
"Mark Adler"
|
||||
],
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"license": "(MIT AND Zlib)",
|
||||
"repository": "nodeca/pako",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/puzrin"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nodeca"
|
||||
}
|
||||
],
|
||||
"main": "./dist/pako.cjs.js",
|
||||
"module": "./dist/pako.mjs",
|
||||
"types": "./dist/pako.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/pako.d.ts",
|
||||
"import": "./dist/pako.mjs",
|
||||
"require": "./dist/pako.cjs.js"
|
||||
},
|
||||
"./browser": {
|
||||
"types": "./dist/pako.d.ts",
|
||||
"import": "./dist/browser/pako.esm.min.mjs",
|
||||
"require": "./dist/browser/pako.umd.min.js",
|
||||
"default": "./dist/browser/pako.umd.min.js"
|
||||
},
|
||||
"./browser/deflate": {
|
||||
"types": "./dist/pako.d.ts",
|
||||
"import": "./dist/browser/pako_deflate.esm.min.mjs",
|
||||
"require": "./dist/browser/pako_deflate.umd.min.js",
|
||||
"default": "./dist/browser/pako_deflate.umd.min.js"
|
||||
},
|
||||
"./browser/inflate": {
|
||||
"import": "./dist/browser/pako_inflate.esm.min.mjs",
|
||||
"require": "./dist/browser/pako_inflate.umd.min.js",
|
||||
"default": "./dist/browser/pako_inflate.umd.min.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"type-check": "tsc --noEmit",
|
||||
"test": "npm run lint && npm run build && npm run type-check && node --test",
|
||||
"coverage": "npm run lint && c8 -r text -r html node --test",
|
||||
"build": "node support/build-dist.mjs",
|
||||
"build_fixtures": "node support/build_fixtures.mjs",
|
||||
"doc": "typedoc",
|
||||
"gh-doc": "npm run doc && gh-pages -d doc -f",
|
||||
"prepack": "npm test && npm run build && npm run doc",
|
||||
"postpublish": "npm run gh-doc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^26.0.0",
|
||||
"c8": "^11.0.0",
|
||||
"eslint": "^9.39.4",
|
||||
"gh-pages": "^6.3.0",
|
||||
"neostandard": "^0.13.0",
|
||||
"rollup": "^4.62.2",
|
||||
"rollup-plugin-dts": "^6.4.1",
|
||||
"typedoc": "^0.28.19",
|
||||
"typescript": "^6.0.3",
|
||||
"vite": "^8.0.14"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user