UNPKG

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