UNPKG

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