mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
test and references
This commit is contained in:
Vendored
+18
@@ -123,8 +123,19 @@ declare namespace Pako {
|
||||
function ungzip(data: Data, options: InflateFunctionOptions & { to: 'string' }): string;
|
||||
function ungzip(data: Data, options?: InflateFunctionOptions): Uint8Array;
|
||||
|
||||
// https://github.com/nodeca/pako/blob/893381abcafa10fa2081ce60dae7d4d8e873a658/lib/deflate.js
|
||||
class Deflate {
|
||||
constructor(options?: DeflateOptions);
|
||||
level?: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
||||
windowBits?: number;
|
||||
memLevel?: number;
|
||||
strategy?: StrategyValues;
|
||||
dictionary?: any;
|
||||
raw?: boolean;
|
||||
to?: 'string';
|
||||
chunkSize?: number;
|
||||
gzip?: boolean;
|
||||
header?: Header;
|
||||
err: ReturnCodes;
|
||||
msg: string;
|
||||
result: Uint8Array | number[];
|
||||
@@ -133,11 +144,18 @@ declare namespace Pako {
|
||||
push(data: Data | ArrayBuffer, mode?: FlushValues | boolean): boolean;
|
||||
}
|
||||
|
||||
// https://github.com/nodeca/pako/blob/893381abcafa10fa2081ce60dae7d4d8e873a658/lib/inflate.js
|
||||
class Inflate {
|
||||
constructor(options?: InflateOptions);
|
||||
windowBits?: number;
|
||||
dictionary?: any;
|
||||
raw?: boolean;
|
||||
to?: 'string';
|
||||
chunkSize?: number;
|
||||
err: ReturnCodes;
|
||||
msg: string;
|
||||
result: Data;
|
||||
header: Header;
|
||||
onData(chunk: Data): void;
|
||||
onEnd(status: number): void;
|
||||
push(data: Data | ArrayBuffer, mode?: FlushValues | boolean): boolean;
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import pako = require("pako");
|
||||
import * as assert from "assert";
|
||||
|
||||
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 chunk3 = new Uint8Array([101, 111, 121, 131, 141, 151, 161, 171, 181, 191]);
|
||||
|
||||
const deflate = new pako.Deflate({level: 3});
|
||||
const deflate = new pako.Deflate({level: 3, strategy : pako.StrategyValues.Z_HUFFMAN_ONLY});
|
||||
|
||||
deflate.push(chunk1, false);
|
||||
deflate.push(chunk3, pako.FlushValues.Z_PARTIAL_FLUSH);
|
||||
deflate.push(chunk2, true); // true -> last chunk
|
||||
|
||||
if (deflate.err) {
|
||||
if (deflate.err !== pako.ReturnCodes.Z_OK) {
|
||||
throw new Error(deflate.err.toString());
|
||||
}
|
||||
|
||||
@@ -19,3 +22,29 @@ const arr: Uint8Array = pako.deflate('1234');
|
||||
|
||||
const str2: string = pako.inflate('1234', {to: 'string'});
|
||||
const arr2: Uint8Array = pako.inflate('1234');
|
||||
|
||||
const data = ' ';
|
||||
|
||||
const deflator = new pako.Deflate({
|
||||
gzip: true,
|
||||
header: {
|
||||
hcrc: true,
|
||||
time: 1234567,
|
||||
os: 15,
|
||||
name: 'test name',
|
||||
comment: 'test comment',
|
||||
extra: [ 4, 5, 6 ]
|
||||
}
|
||||
});
|
||||
deflator.push(data, true);
|
||||
|
||||
const inflator = new pako.Inflate({ to: 'string' });
|
||||
inflator.push(deflator.result, true);
|
||||
|
||||
assert.equal(inflator.err, 0);
|
||||
assert.equal(inflator.result, data);
|
||||
|
||||
const header = inflator.header;
|
||||
assert.equal(header.time, 1234567);
|
||||
assert.equal(header.os, 15);
|
||||
assert.equal(header.name, 'test name');
|
||||
|
||||
@@ -21,4 +21,4 @@
|
||||
"index.d.ts",
|
||||
"pako-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user