forked from oven-sh/bun-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zlib.d.ts
554 lines (554 loc) · 17.5 KB
/
zlib.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/**
* The `zlib` module provides compression functionality implemented using Gzip,
* Deflate/Inflate, and Brotli.
*
* To access it:
*
* ```js
* const zlib = require('zlib');
* ```
*
* Compression and decompression are built around the Node.js `Streams API`.
*
* Compressing or decompressing a stream (such as a file) can be accomplished by
* piping the source stream through a `zlib` `Transform` stream into a destination
* stream:
*
* ```js
* const { createGzip } = require('zlib');
* const { pipeline } = require('stream');
* const {
* createReadStream,
* createWriteStream
* } = require('fs');
*
* const gzip = createGzip();
* const source = createReadStream('input.txt');
* const destination = createWriteStream('input.txt.gz');
*
* pipeline(source, gzip, destination, (err) => {
* if (err) {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* }
* });
*
* // Or, Promisified
*
* const { promisify } = require('util');
* const pipe = promisify(pipeline);
*
* async function do_gzip(input, output) {
* const gzip = createGzip();
* const source = createReadStream(input);
* const destination = createWriteStream(output);
* await pipe(source, gzip, destination);
* }
*
* do_gzip('input.txt', 'input.txt.gz')
* .catch((err) => {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* });
* ```
*
* It is also possible to compress or decompress data in a single step:
*
* ```js
* const { deflate, unzip } = require('zlib');
*
* const input = '.................................';
* deflate(input, (err, buffer) => {
* if (err) {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* }
* console.log(buffer.toString('base64'));
* });
*
* const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
* unzip(buffer, (err, buffer) => {
* if (err) {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* }
* console.log(buffer.toString());
* });
*
* // Or, Promisified
*
* const { promisify } = require('util');
* const do_unzip = promisify(unzip);
*
* do_unzip(buffer)
* .then((buf) => console.log(buf.toString()))
* .catch((err) => {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* });
* ```
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/zlib.js)
*/
declare module "zlib" {
import * as stream from "node:stream";
interface ZlibOptions {
/**
* @default constants.Z_NO_FLUSH
*/
flush?: number | undefined;
/**
* @default constants.Z_FINISH
*/
finishFlush?: number | undefined;
/**
* @default 16*1024
*/
chunkSize?: number | undefined;
windowBits?: number | undefined;
level?: number | undefined; // compression only
memLevel?: number | undefined; // compression only
strategy?: number | undefined; // compression only
dictionary?: ArrayBufferView | ArrayBuffer | undefined; // deflate/inflate only, empty dictionary by default
info?: boolean | undefined;
maxOutputLength?: number | undefined;
}
interface BrotliOptions {
/**
* @default constants.BROTLI_OPERATION_PROCESS
*/
flush?: number | undefined;
/**
* @default constants.BROTLI_OPERATION_FINISH
*/
finishFlush?: number | undefined;
/**
* @default 16*1024
*/
chunkSize?: number | undefined;
params?:
| {
/**
* Each key is a `constants.BROTLI_*` constant.
*/
[key: number]: boolean | number;
}
| undefined;
maxOutputLength?: number | undefined;
}
interface Zlib {
/** @deprecated Use bytesWritten instead. */
readonly bytesRead: number;
readonly bytesWritten: number;
shell?: boolean | string | undefined;
flush(kind?: number, callback?: () => void): void;
flush(callback?: () => void): void;
}
interface ZlibParams {
params(level: number, strategy: number, callback: () => void): void;
}
interface ZlibReset {
reset(): void;
}
interface BrotliCompress extends stream.Transform, Zlib {}
interface BrotliDecompress extends stream.Transform, Zlib {}
interface Gzip extends stream.Transform, Zlib {}
interface Gunzip extends stream.Transform, Zlib {}
interface Deflate extends stream.Transform, Zlib, ZlibReset, ZlibParams {}
interface Inflate extends stream.Transform, Zlib, ZlibReset {}
interface DeflateRaw extends stream.Transform, Zlib, ZlibReset, ZlibParams {}
interface InflateRaw extends stream.Transform, Zlib, ZlibReset {}
interface Unzip extends stream.Transform, Zlib {}
/**
* Creates and returns a new `BrotliCompress` object.
*/
function createBrotliCompress(options?: BrotliOptions): BrotliCompress;
/**
* Creates and returns a new `BrotliDecompress` object.
*/
function createBrotliDecompress(options?: BrotliOptions): BrotliDecompress;
/**
* Creates and returns a new `Gzip` object.
* See `example`.
*/
function createGzip(options?: ZlibOptions): Gzip;
/**
* Creates and returns a new `Gunzip` object.
*/
function createGunzip(options?: ZlibOptions): Gunzip;
/**
* Creates and returns a new `Deflate` object.
*/
function createDeflate(options?: ZlibOptions): Deflate;
/**
* Creates and returns a new `Inflate` object.
*/
function createInflate(options?: ZlibOptions): Inflate;
/**
* Creates and returns a new `DeflateRaw` object.
*
* An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when `windowBits`is set to 8 for raw deflate streams. zlib would automatically set `windowBits`to 9 if was initially set to 8\. Newer
* versions of zlib will throw an exception,
* so Node.js restored the original behavior of upgrading a value of 8 to 9,
* since passing `windowBits = 9` to zlib actually results in a compressed stream
* that effectively uses an 8-bit window only.
*/
function createDeflateRaw(options?: ZlibOptions): DeflateRaw;
/**
* Creates and returns a new `InflateRaw` object.
*/
function createInflateRaw(options?: ZlibOptions): InflateRaw;
/**
* Creates and returns a new `Unzip` object.
*/
function createUnzip(options?: ZlibOptions): Unzip;
type InputType = string | ArrayBuffer | ArrayBufferView;
type CompressCallback = (error: Error | null, result: Buffer) => void;
/**
*/
function brotliCompress(
buf: InputType,
options: BrotliOptions,
callback: CompressCallback
): void;
function brotliCompress(buf: InputType, callback: CompressCallback): void;
namespace brotliCompress {
function __promisify__(
buffer: InputType,
options?: BrotliOptions
): Promise<Buffer>;
}
/**
* Compress a chunk of data with `BrotliCompress`.
*/
function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer;
/**
*/
function brotliDecompress(
buf: InputType,
options: BrotliOptions,
callback: CompressCallback
): void;
function brotliDecompress(buf: InputType, callback: CompressCallback): void;
namespace brotliDecompress {
function __promisify__(
buffer: InputType,
options?: BrotliOptions
): Promise<Buffer>;
}
/**
* Decompress a chunk of data with `BrotliDecompress`.
*/
function brotliDecompressSync(
buf: InputType,
options?: BrotliOptions
): Buffer;
/**
*/
function deflate(buf: InputType, callback: CompressCallback): void;
function deflate(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace deflate {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Compress a chunk of data with `Deflate`.
*/
function deflateSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
*/
function deflateRaw(buf: InputType, callback: CompressCallback): void;
function deflateRaw(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace deflateRaw {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Compress a chunk of data with `DeflateRaw`.
*/
function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
*/
function gzip(buf: InputType, callback: CompressCallback): void;
function gzip(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace gzip {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Compress a chunk of data with `Gzip`.
*/
function gzipSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
*/
function gunzip(buf: InputType, callback: CompressCallback): void;
function gunzip(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace gunzip {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Decompress a chunk of data with `Gunzip`.
*/
function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
*/
function inflate(buf: InputType, callback: CompressCallback): void;
function inflate(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace inflate {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Decompress a chunk of data with `Inflate`.
*/
function inflateSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
*/
function inflateRaw(buf: InputType, callback: CompressCallback): void;
function inflateRaw(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace inflateRaw {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Decompress a chunk of data with `InflateRaw`.
*/
function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
*/
function unzip(buf: InputType, callback: CompressCallback): void;
function unzip(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
namespace unzip {
function __promisify__(
buffer: InputType,
options?: ZlibOptions
): Promise<Buffer>;
}
/**
* Decompress a chunk of data with `Unzip`.
*/
function unzipSync(buf: InputType, options?: ZlibOptions): Buffer;
namespace constants {
const BROTLI_DECODE: number;
const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number;
const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: number;
const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: number;
const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: number;
const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: number;
const BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: number;
const BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: number;
const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: number;
const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: number;
const BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: number;
const BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: number;
const BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: number;
const BROTLI_DECODER_ERROR_FORMAT_DISTANCE: number;
const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: number;
const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: number;
const BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: number;
const BROTLI_DECODER_ERROR_FORMAT_PADDING_1: number;
const BROTLI_DECODER_ERROR_FORMAT_PADDING_2: number;
const BROTLI_DECODER_ERROR_FORMAT_RESERVED: number;
const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: number;
const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: number;
const BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: number;
const BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: number;
const BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: number;
const BROTLI_DECODER_ERROR_UNREACHABLE: number;
const BROTLI_DECODER_NEEDS_MORE_INPUT: number;
const BROTLI_DECODER_NEEDS_MORE_OUTPUT: number;
const BROTLI_DECODER_NO_ERROR: number;
const BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: number;
const BROTLI_DECODER_PARAM_LARGE_WINDOW: number;
const BROTLI_DECODER_RESULT_ERROR: number;
const BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: number;
const BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: number;
const BROTLI_DECODER_RESULT_SUCCESS: number;
const BROTLI_DECODER_SUCCESS: number;
const BROTLI_DEFAULT_MODE: number;
const BROTLI_DEFAULT_QUALITY: number;
const BROTLI_DEFAULT_WINDOW: number;
const BROTLI_ENCODE: number;
const BROTLI_LARGE_MAX_WINDOW_BITS: number;
const BROTLI_MAX_INPUT_BLOCK_BITS: number;
const BROTLI_MAX_QUALITY: number;
const BROTLI_MAX_WINDOW_BITS: number;
const BROTLI_MIN_INPUT_BLOCK_BITS: number;
const BROTLI_MIN_QUALITY: number;
const BROTLI_MIN_WINDOW_BITS: number;
const BROTLI_MODE_FONT: number;
const BROTLI_MODE_GENERIC: number;
const BROTLI_MODE_TEXT: number;
const BROTLI_OPERATION_EMIT_METADATA: number;
const BROTLI_OPERATION_FINISH: number;
const BROTLI_OPERATION_FLUSH: number;
const BROTLI_OPERATION_PROCESS: number;
const BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: number;
const BROTLI_PARAM_LARGE_WINDOW: number;
const BROTLI_PARAM_LGBLOCK: number;
const BROTLI_PARAM_LGWIN: number;
const BROTLI_PARAM_MODE: number;
const BROTLI_PARAM_NDIRECT: number;
const BROTLI_PARAM_NPOSTFIX: number;
const BROTLI_PARAM_QUALITY: number;
const BROTLI_PARAM_SIZE_HINT: number;
const DEFLATE: number;
const DEFLATERAW: number;
const GUNZIP: number;
const GZIP: number;
const INFLATE: number;
const INFLATERAW: number;
const UNZIP: number;
// Allowed flush values.
const Z_NO_FLUSH: number;
const Z_PARTIAL_FLUSH: number;
const Z_SYNC_FLUSH: number;
const Z_FULL_FLUSH: number;
const Z_FINISH: number;
const Z_BLOCK: number;
const Z_TREES: number;
// Return codes for the compression/decompression functions.
// Negative values are errors, positive values are used for special but normal events.
const Z_OK: number;
const Z_STREAM_END: number;
const Z_NEED_DICT: number;
const Z_ERRNO: number;
const Z_STREAM_ERROR: number;
const Z_DATA_ERROR: number;
const Z_MEM_ERROR: number;
const Z_BUF_ERROR: number;
const Z_VERSION_ERROR: number;
// Compression levels.
const Z_NO_COMPRESSION: number;
const Z_BEST_SPEED: number;
const Z_BEST_COMPRESSION: number;
const Z_DEFAULT_COMPRESSION: number;
// Compression strategy.
const Z_FILTERED: number;
const Z_HUFFMAN_ONLY: number;
const Z_RLE: number;
const Z_FIXED: number;
const Z_DEFAULT_STRATEGY: number;
const Z_DEFAULT_WINDOWBITS: number;
const Z_MIN_WINDOWBITS: number;
const Z_MAX_WINDOWBITS: number;
const Z_MIN_CHUNK: number;
const Z_MAX_CHUNK: number;
const Z_DEFAULT_CHUNK: number;
const Z_MIN_MEMLEVEL: number;
const Z_MAX_MEMLEVEL: number;
const Z_DEFAULT_MEMLEVEL: number;
const Z_MIN_LEVEL: number;
const Z_MAX_LEVEL: number;
const Z_DEFAULT_LEVEL: number;
const ZLIB_VERNUM: number;
}
// Allowed flush values.
/** @deprecated Use `constants.Z_NO_FLUSH` */
const Z_NO_FLUSH: number;
/** @deprecated Use `constants.Z_PARTIAL_FLUSH` */
const Z_PARTIAL_FLUSH: number;
/** @deprecated Use `constants.Z_SYNC_FLUSH` */
const Z_SYNC_FLUSH: number;
/** @deprecated Use `constants.Z_FULL_FLUSH` */
const Z_FULL_FLUSH: number;
/** @deprecated Use `constants.Z_FINISH` */
const Z_FINISH: number;
/** @deprecated Use `constants.Z_BLOCK` */
const Z_BLOCK: number;
/** @deprecated Use `constants.Z_TREES` */
const Z_TREES: number;
// Return codes for the compression/decompression functions.
// Negative values are errors, positive values are used for special but normal events.
/** @deprecated Use `constants.Z_OK` */
const Z_OK: number;
/** @deprecated Use `constants.Z_STREAM_END` */
const Z_STREAM_END: number;
/** @deprecated Use `constants.Z_NEED_DICT` */
const Z_NEED_DICT: number;
/** @deprecated Use `constants.Z_ERRNO` */
const Z_ERRNO: number;
/** @deprecated Use `constants.Z_STREAM_ERROR` */
const Z_STREAM_ERROR: number;
/** @deprecated Use `constants.Z_DATA_ERROR` */
const Z_DATA_ERROR: number;
/** @deprecated Use `constants.Z_MEM_ERROR` */
const Z_MEM_ERROR: number;
/** @deprecated Use `constants.Z_BUF_ERROR` */
const Z_BUF_ERROR: number;
/** @deprecated Use `constants.Z_VERSION_ERROR` */
const Z_VERSION_ERROR: number;
// Compression levels.
/** @deprecated Use `constants.Z_NO_COMPRESSION` */
const Z_NO_COMPRESSION: number;
/** @deprecated Use `constants.Z_BEST_SPEED` */
const Z_BEST_SPEED: number;
/** @deprecated Use `constants.Z_BEST_COMPRESSION` */
const Z_BEST_COMPRESSION: number;
/** @deprecated Use `constants.Z_DEFAULT_COMPRESSION` */
const Z_DEFAULT_COMPRESSION: number;
// Compression strategy.
/** @deprecated Use `constants.Z_FILTERED` */
const Z_FILTERED: number;
/** @deprecated Use `constants.Z_HUFFMAN_ONLY` */
const Z_HUFFMAN_ONLY: number;
/** @deprecated Use `constants.Z_RLE` */
const Z_RLE: number;
/** @deprecated Use `constants.Z_FIXED` */
const Z_FIXED: number;
/** @deprecated Use `constants.Z_DEFAULT_STRATEGY` */
const Z_DEFAULT_STRATEGY: number;
/** @deprecated */
const Z_BINARY: number;
/** @deprecated */
const Z_TEXT: number;
/** @deprecated */
const Z_ASCII: number;
/** @deprecated */
const Z_UNKNOWN: number;
/** @deprecated */
const Z_DEFLATED: number;
}
declare module "node:zlib" {
export * from "zlib";
}