UNPKG

14.4 kBTypeScriptView Raw
1declare module 'node:zlib' {
2 export * from 'zlib';
3}
4
5declare module 'zlib' {
6 import * as stream from 'node:stream';
7
8 interface ZlibOptions {
9 /**
10 * @default constants.Z_NO_FLUSH
11 */
12 flush?: number;
13 /**
14 * @default constants.Z_FINISH
15 */
16 finishFlush?: number;
17 /**
18 * @default 16*1024
19 */
20 chunkSize?: number;
21 windowBits?: number;
22 level?: number; // compression only
23 memLevel?: number; // compression only
24 strategy?: number; // compression only
25 dictionary?: NodeJS.ArrayBufferView | ArrayBuffer; // deflate/inflate only, empty dictionary by default
26 info?: boolean;
27 maxOutputLength?: number;
28 }
29
30 interface BrotliOptions {
31 /**
32 * @default constants.BROTLI_OPERATION_PROCESS
33 */
34 flush?: number;
35 /**
36 * @default constants.BROTLI_OPERATION_FINISH
37 */
38 finishFlush?: number;
39 /**
40 * @default 16*1024
41 */
42 chunkSize?: number;
43 params?: {
44 /**
45 * Each key is a `constants.BROTLI_*` constant.
46 */
47 [key: number]: boolean | number;
48 };
49 maxOutputLength?: number;
50 }
51
52 interface Zlib {
53 /** @deprecated Use bytesWritten instead. */
54 readonly bytesRead: number;
55 readonly bytesWritten: number;
56 shell?: boolean | string;
57 close(callback?: () => void): void;
58 flush(kind?: number, callback?: () => void): void;
59 flush(callback?: () => void): void;
60 }
61
62 interface ZlibParams {
63 params(level: number, strategy: number, callback: () => void): void;
64 }
65
66 interface ZlibReset {
67 reset(): void;
68 }
69
70 interface BrotliCompress extends stream.Transform, Zlib { }
71 interface BrotliDecompress extends stream.Transform, Zlib { }
72 interface Gzip extends stream.Transform, Zlib { }
73 interface Gunzip extends stream.Transform, Zlib { }
74 interface Deflate extends stream.Transform, Zlib, ZlibReset, ZlibParams { }
75 interface Inflate extends stream.Transform, Zlib, ZlibReset { }
76 interface DeflateRaw extends stream.Transform, Zlib, ZlibReset, ZlibParams { }
77 interface InflateRaw extends stream.Transform, Zlib, ZlibReset { }
78 interface Unzip extends stream.Transform, Zlib { }
79
80 function createBrotliCompress(options?: BrotliOptions): BrotliCompress;
81 function createBrotliDecompress(options?: BrotliOptions): BrotliDecompress;
82 function createGzip(options?: ZlibOptions): Gzip;
83 function createGunzip(options?: ZlibOptions): Gunzip;
84 function createDeflate(options?: ZlibOptions): Deflate;
85 function createInflate(options?: ZlibOptions): Inflate;
86 function createDeflateRaw(options?: ZlibOptions): DeflateRaw;
87 function createInflateRaw(options?: ZlibOptions): InflateRaw;
88 function createUnzip(options?: ZlibOptions): Unzip;
89
90 type InputType = string | ArrayBuffer | NodeJS.ArrayBufferView;
91
92 type CompressCallback = (error: Error | null, result: Buffer) => void;
93
94 function brotliCompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void;
95 function brotliCompress(buf: InputType, callback: CompressCallback): void;
96 namespace brotliCompress {
97 function __promisify__(buffer: InputType, options?: BrotliOptions): Promise<Buffer>;
98 }
99
100 function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer;
101
102 function brotliDecompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void;
103 function brotliDecompress(buf: InputType, callback: CompressCallback): void;
104 namespace brotliDecompress {
105 function __promisify__(buffer: InputType, options?: BrotliOptions): Promise<Buffer>;
106 }
107
108 function brotliDecompressSync(buf: InputType, options?: BrotliOptions): Buffer;
109
110 function deflate(buf: InputType, callback: CompressCallback): void;
111 function deflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
112 namespace deflate {
113 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
114 }
115
116 function deflateSync(buf: InputType, options?: ZlibOptions): Buffer;
117
118 function deflateRaw(buf: InputType, callback: CompressCallback): void;
119 function deflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
120 namespace deflateRaw {
121 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
122 }
123
124 function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
125
126 function gzip(buf: InputType, callback: CompressCallback): void;
127 function gzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
128 namespace gzip {
129 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
130 }
131
132 function gzipSync(buf: InputType, options?: ZlibOptions): Buffer;
133
134 function gunzip(buf: InputType, callback: CompressCallback): void;
135 function gunzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
136 namespace gunzip {
137 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
138 }
139
140 function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer;
141
142 function inflate(buf: InputType, callback: CompressCallback): void;
143 function inflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
144 namespace inflate {
145 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
146 }
147
148 function inflateSync(buf: InputType, options?: ZlibOptions): Buffer;
149
150 function inflateRaw(buf: InputType, callback: CompressCallback): void;
151 function inflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
152 namespace inflateRaw {
153 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
154 }
155
156 function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
157
158 function unzip(buf: InputType, callback: CompressCallback): void;
159 function unzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
160 namespace unzip {
161 function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
162 }
163
164 function unzipSync(buf: InputType, options?: ZlibOptions): Buffer;
165
166 namespace constants {
167 const BROTLI_DECODE: number;
168 const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number;
169 const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: number;
170 const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: number;
171 const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: number;
172 const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: number;
173 const BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: number;
174 const BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: number;
175 const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: number;
176 const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: number;
177 const BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: number;
178 const BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: number;
179 const BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: number;
180 const BROTLI_DECODER_ERROR_FORMAT_DISTANCE: number;
181 const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: number;
182 const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: number;
183 const BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: number;
184 const BROTLI_DECODER_ERROR_FORMAT_PADDING_1: number;
185 const BROTLI_DECODER_ERROR_FORMAT_PADDING_2: number;
186 const BROTLI_DECODER_ERROR_FORMAT_RESERVED: number;
187 const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: number;
188 const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: number;
189 const BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: number;
190 const BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: number;
191 const BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: number;
192 const BROTLI_DECODER_ERROR_UNREACHABLE: number;
193 const BROTLI_DECODER_NEEDS_MORE_INPUT: number;
194 const BROTLI_DECODER_NEEDS_MORE_OUTPUT: number;
195 const BROTLI_DECODER_NO_ERROR: number;
196 const BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: number;
197 const BROTLI_DECODER_PARAM_LARGE_WINDOW: number;
198 const BROTLI_DECODER_RESULT_ERROR: number;
199 const BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: number;
200 const BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: number;
201 const BROTLI_DECODER_RESULT_SUCCESS: number;
202 const BROTLI_DECODER_SUCCESS: number;
203
204 const BROTLI_DEFAULT_MODE: number;
205 const BROTLI_DEFAULT_QUALITY: number;
206 const BROTLI_DEFAULT_WINDOW: number;
207 const BROTLI_ENCODE: number;
208 const BROTLI_LARGE_MAX_WINDOW_BITS: number;
209 const BROTLI_MAX_INPUT_BLOCK_BITS: number;
210 const BROTLI_MAX_QUALITY: number;
211 const BROTLI_MAX_WINDOW_BITS: number;
212 const BROTLI_MIN_INPUT_BLOCK_BITS: number;
213 const BROTLI_MIN_QUALITY: number;
214 const BROTLI_MIN_WINDOW_BITS: number;
215
216 const BROTLI_MODE_FONT: number;
217 const BROTLI_MODE_GENERIC: number;
218 const BROTLI_MODE_TEXT: number;
219
220 const BROTLI_OPERATION_EMIT_METADATA: number;
221 const BROTLI_OPERATION_FINISH: number;
222 const BROTLI_OPERATION_FLUSH: number;
223 const BROTLI_OPERATION_PROCESS: number;
224
225 const BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: number;
226 const BROTLI_PARAM_LARGE_WINDOW: number;
227 const BROTLI_PARAM_LGBLOCK: number;
228 const BROTLI_PARAM_LGWIN: number;
229 const BROTLI_PARAM_MODE: number;
230 const BROTLI_PARAM_NDIRECT: number;
231 const BROTLI_PARAM_NPOSTFIX: number;
232 const BROTLI_PARAM_QUALITY: number;
233 const BROTLI_PARAM_SIZE_HINT: number;
234
235 const DEFLATE: number;
236 const DEFLATERAW: number;
237 const GUNZIP: number;
238 const GZIP: number;
239 const INFLATE: number;
240 const INFLATERAW: number;
241 const UNZIP: number;
242
243 // Allowed flush values.
244 const Z_NO_FLUSH: number;
245 const Z_PARTIAL_FLUSH: number;
246 const Z_SYNC_FLUSH: number;
247 const Z_FULL_FLUSH: number;
248 const Z_FINISH: number;
249 const Z_BLOCK: number;
250 const Z_TREES: number;
251
252 // Return codes for the compression/decompression functions.
253 // Negative values are errors, positive values are used for special but normal events.
254 const Z_OK: number;
255 const Z_STREAM_END: number;
256 const Z_NEED_DICT: number;
257 const Z_ERRNO: number;
258 const Z_STREAM_ERROR: number;
259 const Z_DATA_ERROR: number;
260 const Z_MEM_ERROR: number;
261 const Z_BUF_ERROR: number;
262 const Z_VERSION_ERROR: number;
263
264 // Compression levels.
265 const Z_NO_COMPRESSION: number;
266 const Z_BEST_SPEED: number;
267 const Z_BEST_COMPRESSION: number;
268 const Z_DEFAULT_COMPRESSION: number;
269
270 // Compression strategy.
271 const Z_FILTERED: number;
272 const Z_HUFFMAN_ONLY: number;
273 const Z_RLE: number;
274 const Z_FIXED: number;
275 const Z_DEFAULT_STRATEGY: number;
276
277 const Z_DEFAULT_WINDOWBITS: number;
278 const Z_MIN_WINDOWBITS: number;
279 const Z_MAX_WINDOWBITS: number;
280
281 const Z_MIN_CHUNK: number;
282 const Z_MAX_CHUNK: number;
283 const Z_DEFAULT_CHUNK: number;
284
285 const Z_MIN_MEMLEVEL: number;
286 const Z_MAX_MEMLEVEL: number;
287 const Z_DEFAULT_MEMLEVEL: number;
288
289 const Z_MIN_LEVEL: number;
290 const Z_MAX_LEVEL: number;
291 const Z_DEFAULT_LEVEL: number;
292
293 const ZLIB_VERNUM: number;
294 }
295
296 // Allowed flush values.
297 /** @deprecated Use `constants.Z_NO_FLUSH` */
298 const Z_NO_FLUSH: number;
299 /** @deprecated Use `constants.Z_PARTIAL_FLUSH` */
300 const Z_PARTIAL_FLUSH: number;
301 /** @deprecated Use `constants.Z_SYNC_FLUSH` */
302 const Z_SYNC_FLUSH: number;
303 /** @deprecated Use `constants.Z_FULL_FLUSH` */
304 const Z_FULL_FLUSH: number;
305 /** @deprecated Use `constants.Z_FINISH` */
306 const Z_FINISH: number;
307 /** @deprecated Use `constants.Z_BLOCK` */
308 const Z_BLOCK: number;
309 /** @deprecated Use `constants.Z_TREES` */
310 const Z_TREES: number;
311
312 // Return codes for the compression/decompression functions.
313 // Negative values are errors, positive values are used for special but normal events.
314 /** @deprecated Use `constants.Z_OK` */
315 const Z_OK: number;
316 /** @deprecated Use `constants.Z_STREAM_END` */
317 const Z_STREAM_END: number;
318 /** @deprecated Use `constants.Z_NEED_DICT` */
319 const Z_NEED_DICT: number;
320 /** @deprecated Use `constants.Z_ERRNO` */
321 const Z_ERRNO: number;
322 /** @deprecated Use `constants.Z_STREAM_ERROR` */
323 const Z_STREAM_ERROR: number;
324 /** @deprecated Use `constants.Z_DATA_ERROR` */
325 const Z_DATA_ERROR: number;
326 /** @deprecated Use `constants.Z_MEM_ERROR` */
327 const Z_MEM_ERROR: number;
328 /** @deprecated Use `constants.Z_BUF_ERROR` */
329 const Z_BUF_ERROR: number;
330 /** @deprecated Use `constants.Z_VERSION_ERROR` */
331 const Z_VERSION_ERROR: number;
332
333 // Compression levels.
334 /** @deprecated Use `constants.Z_NO_COMPRESSION` */
335 const Z_NO_COMPRESSION: number;
336 /** @deprecated Use `constants.Z_BEST_SPEED` */
337 const Z_BEST_SPEED: number;
338 /** @deprecated Use `constants.Z_BEST_COMPRESSION` */
339 const Z_BEST_COMPRESSION: number;
340 /** @deprecated Use `constants.Z_DEFAULT_COMPRESSION` */
341 const Z_DEFAULT_COMPRESSION: number;
342
343 // Compression strategy.
344 /** @deprecated Use `constants.Z_FILTERED` */
345 const Z_FILTERED: number;
346 /** @deprecated Use `constants.Z_HUFFMAN_ONLY` */
347 const Z_HUFFMAN_ONLY: number;
348 /** @deprecated Use `constants.Z_RLE` */
349 const Z_RLE: number;
350 /** @deprecated Use `constants.Z_FIXED` */
351 const Z_FIXED: number;
352 /** @deprecated Use `constants.Z_DEFAULT_STRATEGY` */
353 const Z_DEFAULT_STRATEGY: number;
354
355 /** @deprecated */
356 const Z_BINARY: number;
357 /** @deprecated */
358 const Z_TEXT: number;
359 /** @deprecated */
360 const Z_ASCII: number;
361 /** @deprecated */
362 const Z_UNKNOWN: number;
363 /** @deprecated */
364 const Z_DEFLATED: number;
365}