UNPKG

5.03 kBTypeScriptView Raw
1export = Pako;
2export as namespace pako;
3
4declare namespace Pako {
5 enum constants {
6 // FlushValues
7 Z_NO_FLUSH = 0,
8 Z_PARTIAL_FLUSH = 1,
9 Z_SYNC_FLUSH = 2,
10 Z_FULL_FLUSH = 3,
11 Z_FINISH = 4,
12 Z_BLOCK = 5,
13 Z_TREES = 6,
14 // StrategyValues
15 Z_FILTERED = 1,
16 Z_HUFFMAN_ONLY = 2,
17 Z_RLE = 3,
18 Z_FIXED = 4,
19 Z_DEFAULT_STRATEGY = 0,
20 // ReturnCodes
21 Z_OK = 0,
22 Z_STREAM_END = 1,
23 Z_NEED_DICT = 2,
24 Z_ERRNO = -1,
25 Z_STREAM_ERROR = -2,
26 Z_DATA_ERROR = -3,
27 Z_BUF_ERROR = -5,
28 }
29
30 type FlushValues =
31 | constants.Z_NO_FLUSH
32 | constants.Z_PARTIAL_FLUSH
33 | constants.Z_SYNC_FLUSH
34 | constants.Z_FINISH
35 | constants.Z_BLOCK
36 | constants.Z_TREES;
37
38 type StrategyValues =
39 | constants.Z_FILTERED
40 | constants.Z_HUFFMAN_ONLY
41 | constants.Z_RLE
42 | constants.Z_FIXED
43 | constants.Z_DEFAULT_STRATEGY;
44
45 type ReturnCodes =
46 | constants.Z_OK
47 | constants.Z_STREAM_END
48 | constants.Z_NEED_DICT
49 | constants.Z_ERRNO
50 | constants.Z_STREAM_ERROR
51 | constants.Z_DATA_ERROR
52 | constants.Z_BUF_ERROR
53 | constants.Z_DEFAULT_STRATEGY;
54
55 interface DeflateOptions {
56 level?: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined;
57 windowBits?: number | undefined;
58 memLevel?: number | undefined;
59 strategy?: StrategyValues | undefined;
60 dictionary?: any;
61 raw?: boolean | undefined;
62 chunkSize?: number | undefined;
63 gzip?: boolean | undefined;
64 header?: Header | undefined;
65 }
66
67 interface DeflateFunctionOptions {
68 level?: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined;
69 windowBits?: number | undefined;
70 memLevel?: number | undefined;
71 strategy?: StrategyValues | undefined;
72 dictionary?: any;
73 raw?: boolean | undefined;
74 }
75
76 interface InflateOptions {
77 windowBits?: number | undefined;
78 dictionary?: any;
79 raw?: boolean | undefined;
80 to?: "string" | undefined;
81 chunkSize?: number | undefined;
82 }
83
84 interface InflateFunctionOptions {
85 windowBits?: number | undefined;
86 raw?: boolean | undefined;
87 to?: "string" | undefined;
88 }
89
90 interface Header {
91 text?: boolean | undefined;
92 time?: number | undefined;
93 os?: number | undefined;
94 extra?: number[] | undefined;
95 name?: string | undefined;
96 comment?: string | undefined;
97 hcrc?: boolean | undefined;
98 }
99
100 type Data = Uint8Array | ArrayBuffer;
101
102 /**
103 * Compress data with deflate algorithm and options.
104 */
105 function deflate(data: Data | string, options?: DeflateFunctionOptions): Uint8Array;
106
107 /**
108 * The same as deflate, but creates raw data, without wrapper (header and adler32 crc).
109 */
110 function deflateRaw(data: Data | string, options?: DeflateFunctionOptions): Uint8Array;
111
112 /**
113 * The same as deflate, but create gzip wrapper instead of deflate one.
114 */
115 function gzip(data: Data | string, options?: DeflateFunctionOptions): Uint8Array;
116
117 /**
118 * Decompress data with inflate/ungzip and options. Autodetect format via wrapper header
119 * by default. That's why we don't provide separate ungzip method.
120 */
121 function inflate(data: Data, options: InflateFunctionOptions & { to: "string" }): string;
122 function inflate(data: Data, options?: InflateFunctionOptions): Uint8Array;
123
124 /**
125 * The same as inflate, but creates raw data, without wrapper (header and adler32 crc).
126 */
127 function inflateRaw(data: Data, options: InflateFunctionOptions & { to: "string" }): string;
128 function inflateRaw(data: Data, options?: InflateFunctionOptions): Uint8Array;
129
130 /**
131 * Just shortcut to inflate, because it autodetects format by header.content. Done for convenience.
132 */
133 function ungzip(data: Data, options: InflateFunctionOptions & { to: "string" }): string;
134 function ungzip(data: Data, options?: InflateFunctionOptions): Uint8Array;
135
136 // https://github.com/nodeca/pako/blob/893381abcafa10fa2081ce60dae7d4d8e873a658/lib/deflate.js
137 class Deflate {
138 constructor(options?: DeflateOptions);
139 err: ReturnCodes;
140 msg: string;
141 result: Uint8Array;
142 onData(chunk: Data): void;
143 onEnd(status: number): void;
144 push(data: Data | string, mode?: FlushValues | boolean): boolean;
145 }
146
147 // https://github.com/nodeca/pako/blob/893381abcafa10fa2081ce60dae7d4d8e873a658/lib/inflate.js
148 class Inflate {
149 constructor(options?: InflateOptions);
150 header?: Header | undefined;
151 err: ReturnCodes;
152 msg: string;
153 result: Uint8Array | string;
154 onData(chunk: Data): void;
155 onEnd(status: number): void;
156 push(data: Data, mode?: FlushValues | boolean): boolean;
157 }
158}