UNPKG

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