@types/node 16.4.1 → 16.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/zlib.d.ts CHANGED
@@ -1,6 +1,97 @@
1
+ /**
2
+ * The `zlib` module provides compression functionality implemented using Gzip,
3
+ * Deflate/Inflate, and Brotli.
4
+ *
5
+ * To access it:
6
+ *
7
+ * ```js
8
+ * const zlib = require('zlib');
9
+ * ```
10
+ *
11
+ * Compression and decompression are built around the Node.js `Streams API`.
12
+ *
13
+ * Compressing or decompressing a stream (such as a file) can be accomplished by
14
+ * piping the source stream through a `zlib` `Transform` stream into a destination
15
+ * stream:
16
+ *
17
+ * ```js
18
+ * const { createGzip } = require('zlib');
19
+ * const { pipeline } = require('stream');
20
+ * const {
21
+ * createReadStream,
22
+ * createWriteStream
23
+ * } = require('fs');
24
+ *
25
+ * const gzip = createGzip();
26
+ * const source = createReadStream('input.txt');
27
+ * const destination = createWriteStream('input.txt.gz');
28
+ *
29
+ * pipeline(source, gzip, destination, (err) => {
30
+ * if (err) {
31
+ * console.error('An error occurred:', err);
32
+ * process.exitCode = 1;
33
+ * }
34
+ * });
35
+ *
36
+ * // Or, Promisified
37
+ *
38
+ * const { promisify } = require('util');
39
+ * const pipe = promisify(pipeline);
40
+ *
41
+ * async function do_gzip(input, output) {
42
+ * const gzip = createGzip();
43
+ * const source = createReadStream(input);
44
+ * const destination = createWriteStream(output);
45
+ * await pipe(source, gzip, destination);
46
+ * }
47
+ *
48
+ * do_gzip('input.txt', 'input.txt.gz')
49
+ * .catch((err) => {
50
+ * console.error('An error occurred:', err);
51
+ * process.exitCode = 1;
52
+ * });
53
+ * ```
54
+ *
55
+ * It is also possible to compress or decompress data in a single step:
56
+ *
57
+ * ```js
58
+ * const { deflate, unzip } = require('zlib');
59
+ *
60
+ * const input = '.................................';
61
+ * deflate(input, (err, buffer) => {
62
+ * if (err) {
63
+ * console.error('An error occurred:', err);
64
+ * process.exitCode = 1;
65
+ * }
66
+ * console.log(buffer.toString('base64'));
67
+ * });
68
+ *
69
+ * const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
70
+ * unzip(buffer, (err, buffer) => {
71
+ * if (err) {
72
+ * console.error('An error occurred:', err);
73
+ * process.exitCode = 1;
74
+ * }
75
+ * console.log(buffer.toString());
76
+ * });
77
+ *
78
+ * // Or, Promisified
79
+ *
80
+ * const { promisify } = require('util');
81
+ * const do_unzip = promisify(unzip);
82
+ *
83
+ * do_unzip(buffer)
84
+ * .then((buf) => console.log(buf.toString()))
85
+ * .catch((err) => {
86
+ * console.error('An error occurred:', err);
87
+ * process.exitCode = 1;
88
+ * });
89
+ * ```
90
+ * @since v0.5.8
91
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/zlib.js)
92
+ */
1
93
  declare module 'zlib' {
2
94
  import * as stream from 'node:stream';
3
-
4
95
  interface ZlibOptions {
5
96
  /**
6
97
  * @default constants.Z_NO_FLUSH
@@ -22,7 +113,6 @@ declare module 'zlib' {
22
113
  info?: boolean | undefined;
23
114
  maxOutputLength?: number | undefined;
24
115
  }
25
-
26
116
  interface BrotliOptions {
27
117
  /**
28
118
  * @default constants.BROTLI_OPERATION_PROCESS
@@ -36,15 +126,16 @@ declare module 'zlib' {
36
126
  * @default 16*1024
37
127
  */
38
128
  chunkSize?: number | undefined;
39
- params?: {
40
- /**
41
- * Each key is a `constants.BROTLI_*` constant.
42
- */
43
- [key: number]: boolean | number;
44
- } | undefined;
129
+ params?:
130
+ | {
131
+ /**
132
+ * Each key is a `constants.BROTLI_*` constant.
133
+ */
134
+ [key: number]: boolean | number;
135
+ }
136
+ | undefined;
45
137
  maxOutputLength?: number | undefined;
46
138
  }
47
-
48
139
  interface Zlib {
49
140
  /** @deprecated Use bytesWritten instead. */
50
141
  readonly bytesRead: number;
@@ -54,111 +145,192 @@ declare module 'zlib' {
54
145
  flush(kind?: number, callback?: () => void): void;
55
146
  flush(callback?: () => void): void;
56
147
  }
57
-
58
148
  interface ZlibParams {
59
149
  params(level: number, strategy: number, callback: () => void): void;
60
150
  }
61
-
62
151
  interface ZlibReset {
63
152
  reset(): void;
64
153
  }
65
-
66
- interface BrotliCompress extends stream.Transform, Zlib { }
67
- interface BrotliDecompress extends stream.Transform, Zlib { }
68
- interface Gzip extends stream.Transform, Zlib { }
69
- interface Gunzip extends stream.Transform, Zlib { }
70
- interface Deflate extends stream.Transform, Zlib, ZlibReset, ZlibParams { }
71
- interface Inflate extends stream.Transform, Zlib, ZlibReset { }
72
- interface DeflateRaw extends stream.Transform, Zlib, ZlibReset, ZlibParams { }
73
- interface InflateRaw extends stream.Transform, Zlib, ZlibReset { }
74
- interface Unzip extends stream.Transform, Zlib { }
75
-
154
+ interface BrotliCompress extends stream.Transform, Zlib {}
155
+ interface BrotliDecompress extends stream.Transform, Zlib {}
156
+ interface Gzip extends stream.Transform, Zlib {}
157
+ interface Gunzip extends stream.Transform, Zlib {}
158
+ interface Deflate extends stream.Transform, Zlib, ZlibReset, ZlibParams {}
159
+ interface Inflate extends stream.Transform, Zlib, ZlibReset {}
160
+ interface DeflateRaw extends stream.Transform, Zlib, ZlibReset, ZlibParams {}
161
+ interface InflateRaw extends stream.Transform, Zlib, ZlibReset {}
162
+ interface Unzip extends stream.Transform, Zlib {}
163
+ /**
164
+ * Creates and returns a new `BrotliCompress` object.
165
+ * @since v11.7.0, v10.16.0
166
+ */
76
167
  function createBrotliCompress(options?: BrotliOptions): BrotliCompress;
168
+ /**
169
+ * Creates and returns a new `BrotliDecompress` object.
170
+ * @since v11.7.0, v10.16.0
171
+ */
77
172
  function createBrotliDecompress(options?: BrotliOptions): BrotliDecompress;
173
+ /**
174
+ * Creates and returns a new `Gzip` object.
175
+ * See `example`.
176
+ * @since v0.5.8
177
+ */
78
178
  function createGzip(options?: ZlibOptions): Gzip;
179
+ /**
180
+ * Creates and returns a new `Gunzip` object.
181
+ * @since v0.5.8
182
+ */
79
183
  function createGunzip(options?: ZlibOptions): Gunzip;
184
+ /**
185
+ * Creates and returns a new `Deflate` object.
186
+ * @since v0.5.8
187
+ */
80
188
  function createDeflate(options?: ZlibOptions): Deflate;
189
+ /**
190
+ * Creates and returns a new `Inflate` object.
191
+ * @since v0.5.8
192
+ */
81
193
  function createInflate(options?: ZlibOptions): Inflate;
194
+ /**
195
+ * Creates and returns a new `DeflateRaw` object.
196
+ *
197
+ * 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
198
+ * versions of zlib will throw an exception,
199
+ * so Node.js restored the original behavior of upgrading a value of 8 to 9,
200
+ * since passing `windowBits = 9` to zlib actually results in a compressed stream
201
+ * that effectively uses an 8-bit window only.
202
+ * @since v0.5.8
203
+ */
82
204
  function createDeflateRaw(options?: ZlibOptions): DeflateRaw;
205
+ /**
206
+ * Creates and returns a new `InflateRaw` object.
207
+ * @since v0.5.8
208
+ */
83
209
  function createInflateRaw(options?: ZlibOptions): InflateRaw;
210
+ /**
211
+ * Creates and returns a new `Unzip` object.
212
+ * @since v0.5.8
213
+ */
84
214
  function createUnzip(options?: ZlibOptions): Unzip;
85
-
86
215
  type InputType = string | ArrayBuffer | NodeJS.ArrayBufferView;
87
-
88
216
  type CompressCallback = (error: Error | null, result: Buffer) => void;
89
-
217
+ /**
218
+ * @since v11.7.0, v10.16.0
219
+ */
90
220
  function brotliCompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void;
91
221
  function brotliCompress(buf: InputType, callback: CompressCallback): void;
92
222
  namespace brotliCompress {
93
223
  function __promisify__(buffer: InputType, options?: BrotliOptions): Promise<Buffer>;
94
224
  }
95
-
225
+ /**
226
+ * Compress a chunk of data with `BrotliCompress`.
227
+ * @since v11.7.0, v10.16.0
228
+ */
96
229
  function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer;
97
-
230
+ /**
231
+ * @since v11.7.0, v10.16.0
232
+ */
98
233
  function brotliDecompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void;
99
234
  function brotliDecompress(buf: InputType, callback: CompressCallback): void;
100
235
  namespace brotliDecompress {
101
236
  function __promisify__(buffer: InputType, options?: BrotliOptions): Promise<Buffer>;
102
237
  }
103
-
238
+ /**
239
+ * Decompress a chunk of data with `BrotliDecompress`.
240
+ * @since v11.7.0, v10.16.0
241
+ */
104
242
  function brotliDecompressSync(buf: InputType, options?: BrotliOptions): Buffer;
105
-
243
+ /**
244
+ * @since v0.6.0
245
+ */
106
246
  function deflate(buf: InputType, callback: CompressCallback): void;
107
247
  function deflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
108
248
  namespace deflate {
109
249
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
110
250
  }
111
-
251
+ /**
252
+ * Compress a chunk of data with `Deflate`.
253
+ * @since v0.11.12
254
+ */
112
255
  function deflateSync(buf: InputType, options?: ZlibOptions): Buffer;
113
-
256
+ /**
257
+ * @since v0.6.0
258
+ */
114
259
  function deflateRaw(buf: InputType, callback: CompressCallback): void;
115
260
  function deflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
116
261
  namespace deflateRaw {
117
262
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
118
263
  }
119
-
264
+ /**
265
+ * Compress a chunk of data with `DeflateRaw`.
266
+ * @since v0.11.12
267
+ */
120
268
  function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
121
-
269
+ /**
270
+ * @since v0.6.0
271
+ */
122
272
  function gzip(buf: InputType, callback: CompressCallback): void;
123
273
  function gzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
124
274
  namespace gzip {
125
275
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
126
276
  }
127
-
277
+ /**
278
+ * Compress a chunk of data with `Gzip`.
279
+ * @since v0.11.12
280
+ */
128
281
  function gzipSync(buf: InputType, options?: ZlibOptions): Buffer;
129
-
282
+ /**
283
+ * @since v0.6.0
284
+ */
130
285
  function gunzip(buf: InputType, callback: CompressCallback): void;
131
286
  function gunzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
132
287
  namespace gunzip {
133
288
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
134
289
  }
135
-
290
+ /**
291
+ * Decompress a chunk of data with `Gunzip`.
292
+ * @since v0.11.12
293
+ */
136
294
  function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer;
137
-
295
+ /**
296
+ * @since v0.6.0
297
+ */
138
298
  function inflate(buf: InputType, callback: CompressCallback): void;
139
299
  function inflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
140
300
  namespace inflate {
141
301
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
142
302
  }
143
-
303
+ /**
304
+ * Decompress a chunk of data with `Inflate`.
305
+ * @since v0.11.12
306
+ */
144
307
  function inflateSync(buf: InputType, options?: ZlibOptions): Buffer;
145
-
308
+ /**
309
+ * @since v0.6.0
310
+ */
146
311
  function inflateRaw(buf: InputType, callback: CompressCallback): void;
147
312
  function inflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
148
313
  namespace inflateRaw {
149
314
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
150
315
  }
151
-
316
+ /**
317
+ * Decompress a chunk of data with `InflateRaw`.
318
+ * @since v0.11.12
319
+ */
152
320
  function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
153
-
321
+ /**
322
+ * @since v0.6.0
323
+ */
154
324
  function unzip(buf: InputType, callback: CompressCallback): void;
155
325
  function unzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
156
326
  namespace unzip {
157
327
  function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
158
328
  }
159
-
329
+ /**
330
+ * Decompress a chunk of data with `Unzip`.
331
+ * @since v0.11.12
332
+ */
160
333
  function unzipSync(buf: InputType, options?: ZlibOptions): Buffer;
161
-
162
334
  namespace constants {
163
335
  const BROTLI_DECODE: number;
164
336
  const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number;
@@ -196,7 +368,6 @@ declare module 'zlib' {
196
368
  const BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: number;
197
369
  const BROTLI_DECODER_RESULT_SUCCESS: number;
198
370
  const BROTLI_DECODER_SUCCESS: number;
199
-
200
371
  const BROTLI_DEFAULT_MODE: number;
201
372
  const BROTLI_DEFAULT_QUALITY: number;
202
373
  const BROTLI_DEFAULT_WINDOW: number;
@@ -208,16 +379,13 @@ declare module 'zlib' {
208
379
  const BROTLI_MIN_INPUT_BLOCK_BITS: number;
209
380
  const BROTLI_MIN_QUALITY: number;
210
381
  const BROTLI_MIN_WINDOW_BITS: number;
211
-
212
382
  const BROTLI_MODE_FONT: number;
213
383
  const BROTLI_MODE_GENERIC: number;
214
384
  const BROTLI_MODE_TEXT: number;
215
-
216
385
  const BROTLI_OPERATION_EMIT_METADATA: number;
217
386
  const BROTLI_OPERATION_FINISH: number;
218
387
  const BROTLI_OPERATION_FLUSH: number;
219
388
  const BROTLI_OPERATION_PROCESS: number;
220
-
221
389
  const BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: number;
222
390
  const BROTLI_PARAM_LARGE_WINDOW: number;
223
391
  const BROTLI_PARAM_LGBLOCK: number;
@@ -227,7 +395,6 @@ declare module 'zlib' {
227
395
  const BROTLI_PARAM_NPOSTFIX: number;
228
396
  const BROTLI_PARAM_QUALITY: number;
229
397
  const BROTLI_PARAM_SIZE_HINT: number;
230
-
231
398
  const DEFLATE: number;
232
399
  const DEFLATERAW: number;
233
400
  const GUNZIP: number;
@@ -235,7 +402,6 @@ declare module 'zlib' {
235
402
  const INFLATE: number;
236
403
  const INFLATERAW: number;
237
404
  const UNZIP: number;
238
-
239
405
  // Allowed flush values.
240
406
  const Z_NO_FLUSH: number;
241
407
  const Z_PARTIAL_FLUSH: number;
@@ -244,7 +410,6 @@ declare module 'zlib' {
244
410
  const Z_FINISH: number;
245
411
  const Z_BLOCK: number;
246
412
  const Z_TREES: number;
247
-
248
413
  // Return codes for the compression/decompression functions.
249
414
  // Negative values are errors, positive values are used for special but normal events.
250
415
  const Z_OK: number;
@@ -256,39 +421,31 @@ declare module 'zlib' {
256
421
  const Z_MEM_ERROR: number;
257
422
  const Z_BUF_ERROR: number;
258
423
  const Z_VERSION_ERROR: number;
259
-
260
424
  // Compression levels.
261
425
  const Z_NO_COMPRESSION: number;
262
426
  const Z_BEST_SPEED: number;
263
427
  const Z_BEST_COMPRESSION: number;
264
428
  const Z_DEFAULT_COMPRESSION: number;
265
-
266
429
  // Compression strategy.
267
430
  const Z_FILTERED: number;
268
431
  const Z_HUFFMAN_ONLY: number;
269
432
  const Z_RLE: number;
270
433
  const Z_FIXED: number;
271
434
  const Z_DEFAULT_STRATEGY: number;
272
-
273
435
  const Z_DEFAULT_WINDOWBITS: number;
274
436
  const Z_MIN_WINDOWBITS: number;
275
437
  const Z_MAX_WINDOWBITS: number;
276
-
277
438
  const Z_MIN_CHUNK: number;
278
439
  const Z_MAX_CHUNK: number;
279
440
  const Z_DEFAULT_CHUNK: number;
280
-
281
441
  const Z_MIN_MEMLEVEL: number;
282
442
  const Z_MAX_MEMLEVEL: number;
283
443
  const Z_DEFAULT_MEMLEVEL: number;
284
-
285
444
  const Z_MIN_LEVEL: number;
286
445
  const Z_MAX_LEVEL: number;
287
446
  const Z_DEFAULT_LEVEL: number;
288
-
289
447
  const ZLIB_VERNUM: number;
290
448
  }
291
-
292
449
  // Allowed flush values.
293
450
  /** @deprecated Use `constants.Z_NO_FLUSH` */
294
451
  const Z_NO_FLUSH: number;
@@ -304,7 +461,6 @@ declare module 'zlib' {
304
461
  const Z_BLOCK: number;
305
462
  /** @deprecated Use `constants.Z_TREES` */
306
463
  const Z_TREES: number;
307
-
308
464
  // Return codes for the compression/decompression functions.
309
465
  // Negative values are errors, positive values are used for special but normal events.
310
466
  /** @deprecated Use `constants.Z_OK` */
@@ -325,7 +481,6 @@ declare module 'zlib' {
325
481
  const Z_BUF_ERROR: number;
326
482
  /** @deprecated Use `constants.Z_VERSION_ERROR` */
327
483
  const Z_VERSION_ERROR: number;
328
-
329
484
  // Compression levels.
330
485
  /** @deprecated Use `constants.Z_NO_COMPRESSION` */
331
486
  const Z_NO_COMPRESSION: number;
@@ -335,7 +490,6 @@ declare module 'zlib' {
335
490
  const Z_BEST_COMPRESSION: number;
336
491
  /** @deprecated Use `constants.Z_DEFAULT_COMPRESSION` */
337
492
  const Z_DEFAULT_COMPRESSION: number;
338
-
339
493
  // Compression strategy.
340
494
  /** @deprecated Use `constants.Z_FILTERED` */
341
495
  const Z_FILTERED: number;
@@ -347,7 +501,6 @@ declare module 'zlib' {
347
501
  const Z_FIXED: number;
348
502
  /** @deprecated Use `constants.Z_DEFAULT_STRATEGY` */
349
503
  const Z_DEFAULT_STRATEGY: number;
350
-
351
504
  /** @deprecated */
352
505
  const Z_BINARY: number;
353
506
  /** @deprecated */
@@ -359,7 +512,6 @@ declare module 'zlib' {
359
512
  /** @deprecated */
360
513
  const Z_DEFLATED: number;
361
514
  }
362
-
363
515
  declare module 'node:zlib' {
364
516
  export * from 'zlib';
365
517
  }