-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzlib.html
More file actions
944 lines (927 loc) · 63.9 KB
/
zlib.html
File metadata and controls
944 lines (927 loc) · 63.9 KB
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Zlib | Node.js v12.0.0 Documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/hljs.css">
<link rel="canonical" href="https://nodejs.org/api/zlib.html">
</head>
<body class="alt apidoc" id="api-section-zlib">
<div id="content" class="clearfix">
<div id="column2" class="interior">
<div id="intro" class="interior">
<a href="/" title="Go back to the home page">
Node.js
</a>
</div>
<ul>
<li><a href="documentation.html" class="nav-documentation">About these Docs</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage & Example</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="assert.html" class="nav-assert">Assertion Testing</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async Hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ Addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ Addons - N-API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child Processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command Line Options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="esm.html" class="nav-esm">ECMAScript Modules</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File System</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance Hooks</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query Strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String Decoder</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace Events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/Datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker Threads</a></li>
<li><a href="zlib.html" class="nav-zlib active">ZLIB</a></li>
</ul>
<div class="line"></div>
<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">GitHub Repo & Issue Tracker</a></li>
</ul>
</div>
<div id="column1" data-id="zlib" class="interior">
<header>
<h1>Node.js v12.0.0 Documentation</h1>
<div id="gtoc">
<ul>
<li>
<a href="index.html" name="toc">Index</a>
</li>
<li>
<a href="all.html">View on single page</a>
</li>
<li>
<a href="zlib.json">View as JSON</a>
</li>
<li class="version-picker">
<a href="#">View another version <span>▼</span></a>
<ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v11.x/api/zlib.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/zlib.html">10.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/zlib.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/zlib.html">8.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/zlib.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/zlib.html">6.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/zlib.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/zlib.html">4.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/zlib.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/zlib.html">0.10.x</a></li></ol>
</li>
<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/zlib.md"><span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"/></svg></span>Edit on GitHub</a></li>
</ul>
</div>
<hr>
</header>
<div id="toc">
<h2>Table of Contents</h2>
<ul>
<li>
<p><span class="stability_2"><a href="#zlib_zlib">Zlib</a></span></p>
<ul>
<li><a href="#zlib_threadpool_usage">Threadpool Usage</a></li>
<li><a href="#zlib_compressing_http_requests_and_responses">Compressing HTTP requests and responses</a></li>
<li><a href="#zlib_memory_usage_tuning">Memory Usage Tuning</a></li>
<li><a href="#zlib_flushing">Flushing</a></li>
<li><a href="#zlib_constants">Constants</a></li>
<li><a href="#zlib_class_options">Class: Options</a></li>
<li><a href="#zlib_class_zlib_deflate">Class: zlib.Deflate</a></li>
<li><a href="#zlib_class_zlib_deflateraw">Class: zlib.DeflateRaw</a></li>
<li><a href="#zlib_class_zlib_gunzip">Class: zlib.Gunzip</a></li>
<li><a href="#zlib_class_zlib_gzip">Class: zlib.Gzip</a></li>
<li><a href="#zlib_class_zlib_inflate">Class: zlib.Inflate</a></li>
<li><a href="#zlib_class_zlib_inflateraw">Class: zlib.InflateRaw</a></li>
<li><a href="#zlib_class_zlib_unzip">Class: zlib.Unzip</a></li>
<li>
<p><a href="#zlib_class_zlib_zlib">Class: zlib.Zlib</a></p>
<ul>
<li><span class="stability_0"><a href="#zlib_zlib_bytesread">zlib.bytesRead</a></span></li>
<li><a href="#zlib_zlib_byteswritten">zlib.bytesWritten</a></li>
<li><a href="#zlib_zlib_close_callback">zlib.close([callback])</a></li>
<li><a href="#zlib_zlib_flush_kind_callback">zlib.flush([kind, ]callback)</a></li>
<li><a href="#zlib_zlib_params_level_strategy_callback">zlib.params(level, strategy, callback)</a></li>
<li><a href="#zlib_zlib_reset">zlib.reset()</a></li>
</ul>
</li>
<li><a href="#zlib_zlib_constants">zlib.constants</a></li>
<li><a href="#zlib_zlib_createdeflate_options">zlib.createDeflate([options])</a></li>
<li><a href="#zlib_zlib_createdeflateraw_options">zlib.createDeflateRaw([options])</a></li>
<li><a href="#zlib_zlib_creategunzip_options">zlib.createGunzip([options])</a></li>
<li><a href="#zlib_zlib_creategzip_options">zlib.createGzip([options])</a></li>
<li><a href="#zlib_zlib_createinflate_options">zlib.createInflate([options])</a></li>
<li><a href="#zlib_zlib_createinflateraw_options">zlib.createInflateRaw([options])</a></li>
<li><a href="#zlib_zlib_createunzip_options">zlib.createUnzip([options])</a></li>
<li>
<p><a href="#zlib_convenience_methods">Convenience Methods</a></p>
<ul>
<li><a href="#zlib_zlib_deflate_buffer_options_callback">zlib.deflate(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_deflatesync_buffer_options">zlib.deflateSync(buffer[, options])</a></li>
<li><a href="#zlib_zlib_deflateraw_buffer_options_callback">zlib.deflateRaw(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_deflaterawsync_buffer_options">zlib.deflateRawSync(buffer[, options])</a></li>
<li><a href="#zlib_zlib_gunzip_buffer_options_callback">zlib.gunzip(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_gunzipsync_buffer_options">zlib.gunzipSync(buffer[, options])</a></li>
<li><a href="#zlib_zlib_gzip_buffer_options_callback">zlib.gzip(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_gzipsync_buffer_options">zlib.gzipSync(buffer[, options])</a></li>
<li><a href="#zlib_zlib_inflate_buffer_options_callback">zlib.inflate(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_inflatesync_buffer_options">zlib.inflateSync(buffer[, options])</a></li>
<li><a href="#zlib_zlib_inflateraw_buffer_options_callback">zlib.inflateRaw(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_inflaterawsync_buffer_options">zlib.inflateRawSync(buffer[, options])</a></li>
<li><a href="#zlib_zlib_unzip_buffer_options_callback">zlib.unzip(buffer[, options], callback)</a></li>
<li><a href="#zlib_zlib_unzipsync_buffer_options">zlib.unzipSync(buffer[, options])</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div id="apicontent">
<h1>Zlib<span><a class="mark" href="#zlib_zlib" id="zlib_zlib">#</a></span></h1>
<p></p><div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p>
<p>The <code>zlib</code> module provides compression functionality implemented using Gzip and
Deflate/Inflate. It can be accessed using:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);</code></pre>
<p>Compressing or decompressing a stream (such as a file) can be accomplished by
piping the source stream data through a <code>zlib</code> stream into a destination stream:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> gzip = zlib.createGzip();
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
<span class="hljs-keyword">const</span> inp = fs.createReadStream(<span class="hljs-string">'input.txt'</span>);
<span class="hljs-keyword">const</span> out = fs.createWriteStream(<span class="hljs-string">'input.txt.gz'</span>);
inp.pipe(gzip).pipe(out);</code></pre>
<p>It is also possible to compress or decompress data in a single step:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> input = <span class="hljs-string">'.................................'</span>;
zlib.deflate(input, (err, buffer) => {
<span class="hljs-keyword">if</span> (!err) {
<span class="hljs-built_in">console</span>.log(buffer.toString(<span class="hljs-string">'base64'</span>));
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">// handle error</span>
}
});
<span class="hljs-keyword">const</span> buffer = Buffer.from(<span class="hljs-string">'eJzT0yMAAGTvBe8='</span>, <span class="hljs-string">'base64'</span>);
zlib.unzip(buffer, (err, buffer) => {
<span class="hljs-keyword">if</span> (!err) {
<span class="hljs-built_in">console</span>.log(buffer.toString());
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">// handle error</span>
}
});</code></pre>
<h2>Threadpool Usage<span><a class="mark" href="#zlib_threadpool_usage" id="zlib_threadpool_usage">#</a></span></h2>
<p>Note that all zlib APIs except those that are explicitly synchronous use libuv's
threadpool. This can lead to surprising effects in some applications, such as
subpar performance (which can be mitigated by adjusting the <a href="cli.html#cli_uv_threadpool_size_size">pool size</a>)
and/or unrecoverable and catastrophic memory fragmentation.</p>
<h2>Compressing HTTP requests and responses<span><a class="mark" href="#zlib_compressing_http_requests_and_responses" id="zlib_compressing_http_requests_and_responses">#</a></span></h2>
<p>The <code>zlib</code> module can be used to implement support for the <code>gzip</code> and <code>deflate</code>
content-encoding mechanisms defined by
<a href="https://tools.ietf.org/html/rfc7230#section-4.2">HTTP</a>.</p>
<p>The HTTP <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3"><code>Accept-Encoding</code></a> header is used within an http request to identify
the compression encodings accepted by the client. The <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11"><code>Content-Encoding</code></a>
header is used to identify the compression encodings actually applied to a
message.</p>
<p>The examples given below are drastically simplified to show the basic concept.
Using <code>zlib</code> encoding can be expensive, and the results ought to be cached.
See <a href="#zlib_memory_usage_tuning">Memory Usage Tuning</a> for more information on the speed/memory/compression
tradeoffs involved in <code>zlib</code> usage.</p>
<pre><code class="language-js"><span class="hljs-comment">// client request example</span>
<span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
<span class="hljs-keyword">const</span> request = http.get({ <span class="hljs-attr">host</span>: <span class="hljs-string">'example.com'</span>,
<span class="hljs-attr">path</span>: <span class="hljs-string">'/'</span>,
<span class="hljs-attr">port</span>: <span class="hljs-number">80</span>,
<span class="hljs-attr">headers</span>: { <span class="hljs-string">'Accept-Encoding'</span>: <span class="hljs-string">'gzip,deflate'</span> } });
request.on(<span class="hljs-string">'response'</span>, (response) => {
<span class="hljs-keyword">const</span> output = fs.createWriteStream(<span class="hljs-string">'example.com_index.html'</span>);
<span class="hljs-keyword">switch</span> (response.headers[<span class="hljs-string">'content-encoding'</span>]) {
<span class="hljs-comment">// or, just use zlib.createUnzip() to handle both cases</span>
<span class="hljs-keyword">case</span> <span class="hljs-string">'gzip'</span>:
response.pipe(zlib.createGunzip()).pipe(output);
<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">case</span> <span class="hljs-string">'deflate'</span>:
response.pipe(zlib.createInflate()).pipe(output);
<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">default</span>:
response.pipe(output);
<span class="hljs-keyword">break</span>;
}
});</code></pre>
<pre><code class="language-js"><span class="hljs-comment">// server example</span>
<span class="hljs-comment">// Running a gzip operation on every request is quite expensive.</span>
<span class="hljs-comment">// It would be much more efficient to cache the compressed buffer.</span>
<span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
http.createServer(<span class="hljs-function">(<span class="hljs-params">request, response</span>) =></span> {
<span class="hljs-keyword">const</span> raw = fs.createReadStream(<span class="hljs-string">'index.html'</span>);
<span class="hljs-keyword">let</span> acceptEncoding = request.headers[<span class="hljs-string">'accept-encoding'</span>];
<span class="hljs-keyword">if</span> (!acceptEncoding) {
acceptEncoding = <span class="hljs-string">''</span>;
}
<span class="hljs-comment">// Note: This is not a conformant accept-encoding parser.</span>
<span class="hljs-comment">// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3</span>
<span class="hljs-keyword">if</span> (<span class="hljs-regexp">/\bdeflate\b/</span>.test(acceptEncoding)) {
response.writeHead(<span class="hljs-number">200</span>, { <span class="hljs-string">'Content-Encoding'</span>: <span class="hljs-string">'deflate'</span> });
raw.pipe(zlib.createDeflate()).pipe(response);
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/\bgzip\b/</span>.test(acceptEncoding)) {
response.writeHead(<span class="hljs-number">200</span>, { <span class="hljs-string">'Content-Encoding'</span>: <span class="hljs-string">'gzip'</span> });
raw.pipe(zlib.createGzip()).pipe(response);
} <span class="hljs-keyword">else</span> {
response.writeHead(<span class="hljs-number">200</span>, {});
raw.pipe(response);
}
}).listen(<span class="hljs-number">1337</span>);</code></pre>
<p>By default, the <code>zlib</code> methods will throw an error when decompressing
truncated data. However, if it is known that the data is incomplete, or
the desire is to inspect only the beginning of a compressed file, it is
possible to suppress the default error handling by changing the flushing
method that is used to decompress the last chunk of input data:</p>
<pre><code class="language-js"><span class="hljs-comment">// This is a truncated version of the buffer from the above examples</span>
<span class="hljs-keyword">const</span> buffer = Buffer.from(<span class="hljs-string">'eJzT0yMA'</span>, <span class="hljs-string">'base64'</span>);
zlib.unzip(
buffer,
{ <span class="hljs-attr">finishFlush</span>: zlib.constants.Z_SYNC_FLUSH },
(err, buffer) => {
<span class="hljs-keyword">if</span> (!err) {
<span class="hljs-built_in">console</span>.log(buffer.toString());
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">// handle error</span>
}
});</code></pre>
<p>This will not change the behavior in other error-throwing situations, e.g.
when the input data has an invalid format. Using this method, it will not be
possible to determine whether the input ended prematurely or lacks the
integrity checks, making it necessary to manually check that the
decompressed result is valid.</p>
<h2>Memory Usage Tuning<span><a class="mark" href="#zlib_memory_usage_tuning" id="zlib_memory_usage_tuning">#</a></span></h2>
<p>From <code>zlib/zconf.h</code>, modified to Node.js's usage:</p>
<p>The memory requirements for deflate are (in bytes):</p>
<!-- eslint-disable semi -->
<pre><code class="language-js">(<span class="hljs-number">1</span> << (windowBits + <span class="hljs-number">2</span>)) + (<span class="hljs-number">1</span> << (memLevel + <span class="hljs-number">9</span>))</code></pre>
<p>That is: 128K for <code>windowBits</code> = 15 + 128K for <code>memLevel</code> = 8
(default values) plus a few kilobytes for small objects.</p>
<p>For example, to reduce the default memory requirements from 256K to 128K, the
options should be set to:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> options = { <span class="hljs-attr">windowBits</span>: <span class="hljs-number">14</span>, <span class="hljs-attr">memLevel</span>: <span class="hljs-number">7</span> };</code></pre>
<p>This will, however, generally degrade compression.</p>
<p>The memory requirements for inflate are (in bytes) <code>1 << windowBits</code>.
That is, 32K for <code>windowBits</code> = 15 (default value) plus a few kilobytes
for small objects.</p>
<p>This is in addition to a single internal output slab buffer of size
<code>chunkSize</code>, which defaults to 16K.</p>
<p>The speed of <code>zlib</code> compression is affected most dramatically by the
<code>level</code> setting. A higher level will result in better compression, but
will take longer to complete. A lower level will result in less
compression, but will be much faster.</p>
<p>In general, greater memory usage options will mean that Node.js has to make
fewer calls to <code>zlib</code> because it will be able to process more data on
each <code>write</code> operation. So, this is another factor that affects the
speed, at the cost of memory usage.</p>
<h2>Flushing<span><a class="mark" href="#zlib_flushing" id="zlib_flushing">#</a></span></h2>
<p>Calling <a href="#zlib_zlib_flush_kind_callback"><code>.flush()</code></a> on a compression stream will make <code>zlib</code> return as much
output as currently possible. This may come at the cost of degraded compression
quality, but can be useful when data needs to be available as soon as possible.</p>
<p>In the following example, <code>flush()</code> is used to write a compressed partial
HTTP response to the client:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);
http.createServer(<span class="hljs-function">(<span class="hljs-params">request, response</span>) =></span> {
<span class="hljs-comment">// For the sake of simplicity, the Accept-Encoding checks are omitted.</span>
response.writeHead(<span class="hljs-number">200</span>, { <span class="hljs-string">'content-encoding'</span>: <span class="hljs-string">'gzip'</span> });
<span class="hljs-keyword">const</span> output = zlib.createGzip();
output.pipe(response);
setInterval(<span class="hljs-function"><span class="hljs-params">()</span> =></span> {
output.write(<span class="hljs-string">`The current time is <span class="hljs-subst">${<span class="hljs-built_in">Date</span>()}</span>\n`</span>, () => {
<span class="hljs-comment">// The data has been passed to zlib, but the compression algorithm may</span>
<span class="hljs-comment">// have decided to buffer the data for more efficient compression.</span>
<span class="hljs-comment">// Calling .flush() will make the data available as soon as the client</span>
<span class="hljs-comment">// is ready to receive it.</span>
output.flush();
});
}, <span class="hljs-number">1000</span>);
}).listen(<span class="hljs-number">1337</span>);</code></pre>
<h2>Constants<span><a class="mark" href="#zlib_constants" id="zlib_constants">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<p>All of the constants defined in <code>zlib.h</code> are also defined on
<code>require('zlib').constants</code>. In the normal course of operations, it will not be
necessary to use these constants. They are documented so that their presence is
not surprising. This section is taken almost directly from the
<a href="https://zlib.net/manual.html#Constants">zlib documentation</a>. See <a href="https://zlib.net/manual.html#Constants">https://zlib.net/manual.html#Constants</a> for more
details.</p>
<p>Previously, the constants were available directly from <code>require('zlib')</code>, for
instance <code>zlib.Z_NO_FLUSH</code>. Accessing the constants directly from the module is
currently still possible but is deprecated.</p>
<p>Allowed flush values.</p>
<ul>
<li><code>zlib.constants.Z_NO_FLUSH</code></li>
<li><code>zlib.constants.Z_PARTIAL_FLUSH</code></li>
<li><code>zlib.constants.Z_SYNC_FLUSH</code></li>
<li><code>zlib.constants.Z_FULL_FLUSH</code></li>
<li><code>zlib.constants.Z_FINISH</code></li>
<li><code>zlib.constants.Z_BLOCK</code></li>
<li><code>zlib.constants.Z_TREES</code></li>
</ul>
<p>Return codes for the compression/decompression functions. Negative
values are errors, positive values are used for special but normal
events.</p>
<ul>
<li><code>zlib.constants.Z_OK</code></li>
<li><code>zlib.constants.Z_STREAM_END</code></li>
<li><code>zlib.constants.Z_NEED_DICT</code></li>
<li><code>zlib.constants.Z_ERRNO</code></li>
<li><code>zlib.constants.Z_STREAM_ERROR</code></li>
<li><code>zlib.constants.Z_DATA_ERROR</code></li>
<li><code>zlib.constants.Z_MEM_ERROR</code></li>
<li><code>zlib.constants.Z_BUF_ERROR</code></li>
<li><code>zlib.constants.Z_VERSION_ERROR</code></li>
</ul>
<p>Compression levels.</p>
<ul>
<li><code>zlib.constants.Z_NO_COMPRESSION</code></li>
<li><code>zlib.constants.Z_BEST_SPEED</code></li>
<li><code>zlib.constants.Z_BEST_COMPRESSION</code></li>
<li><code>zlib.constants.Z_DEFAULT_COMPRESSION</code></li>
</ul>
<p>Compression strategy.</p>
<ul>
<li><code>zlib.constants.Z_FILTERED</code></li>
<li><code>zlib.constants.Z_HUFFMAN_ONLY</code></li>
<li><code>zlib.constants.Z_RLE</code></li>
<li><code>zlib.constants.Z_FIXED</code></li>
<li><code>zlib.constants.Z_DEFAULT_STRATEGY</code></li>
</ul>
<h2>Class: Options<span><a class="mark" href="#zlib_class_options" id="zlib_class_options">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>dictionary</code> option can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>dictionary</code> option can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v5.11.0</td>
<td><p>The <code>finishFlush</code> option is supported now.</p></td></tr>
<tr><td>v0.11.1</td>
<td><p><span>Added in: v0.11.1</span></p></td></tr>
</tbody></table>
</details>
</div>
<p>Each class takes an <code>options</code> object. All options are optional.</p>
<p>Note that some options are only relevant when compressing, and are
ignored by the decompression classes.</p>
<ul>
<li><code>flush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> <strong>Default:</strong> <code>zlib.constants.Z_NO_FLUSH</code></li>
<li><code>finishFlush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> <strong>Default:</strong> <code>zlib.constants.Z_FINISH</code></li>
<li><code>chunkSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> <strong>Default:</strong> <code>16 * 1024</code></li>
<li><code>windowBits</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>level</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> (compression only)</li>
<li><code>memLevel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> (compression only)</li>
<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> (compression only)</li>
<li><code>dictionary</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> (deflate/inflate only,
empty dictionary by default)</li>
<li><code>info</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> (If <code>true</code>, returns an object with <code>buffer</code> and <code>engine</code>.)</li>
</ul>
<p>See the description of <code>deflateInit2</code> and <code>inflateInit2</code> at
<a href="https://zlib.net/manual.html#Advanced">https://zlib.net/manual.html#Advanced</a> for more information on these.</p>
<h2>Class: zlib.Deflate<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L646">[src]</a><span><a class="mark" href="#zlib_class_zlib_deflate" id="zlib_class_zlib_deflate">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<p>Compress data using deflate.</p>
<h2>Class: zlib.DeflateRaw<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L674">[src]</a><span><a class="mark" href="#zlib_class_zlib_deflateraw" id="zlib_class_zlib_deflateraw">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<p>Compress data using deflate, and do not append a <code>zlib</code> header.</p>
<h2>Class: zlib.Gunzip<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L667">[src]</a><span><a class="mark" href="#zlib_class_zlib_gunzip" id="zlib_class_zlib_gunzip">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v6.0.0</td>
<td><p>Trailing garbage at the end of the input stream will now result in an <code>'error'</code> event.</p></td></tr>
<tr><td>v5.9.0</td>
<td><p>Multiple concatenated gzip file members are supported now.</p></td></tr>
<tr><td>v5.0.0</td>
<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
<tr><td>v0.5.8</td>
<td><p><span>Added in: v0.5.8</span></p></td></tr>
</tbody></table>
</details>
</div>
<p>Decompress a gzip stream.</p>
<h2>Class: zlib.Gzip<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L660">[src]</a><span><a class="mark" href="#zlib_class_zlib_gzip" id="zlib_class_zlib_gzip">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<p>Compress data using gzip.</p>
<h2>Class: zlib.Inflate<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L653">[src]</a><span><a class="mark" href="#zlib_class_zlib_inflate" id="zlib_class_zlib_inflate">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v5.0.0</td>
<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
<tr><td>v0.5.8</td>
<td><p><span>Added in: v0.5.8</span></p></td></tr>
</tbody></table>
</details>
</div>
<p>Decompress a deflate stream.</p>
<h2>Class: zlib.InflateRaw<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L682">[src]</a><span><a class="mark" href="#zlib_class_zlib_inflateraw" id="zlib_class_zlib_inflateraw">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v6.8.0</td>
<td><p>Custom dictionaries are now supported by <code>InflateRaw</code>.</p></td></tr>
<tr><td>v5.0.0</td>
<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
<tr><td>v0.5.8</td>
<td><p><span>Added in: v0.5.8</span></p></td></tr>
</tbody></table>
</details>
</div>
<p>Decompress a raw deflate stream.</p>
<h2>Class: zlib.Unzip<a class="srclink" href="https://github.com/runkitdev/node/blob/cf1ce2bcc1a88ef6ff1bf745a19913a69607fb02/lib/zlib.js#L689">[src]</a><span><a class="mark" href="#zlib_class_zlib_unzip" id="zlib_class_zlib_unzip">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<p>Decompress either a Gzip- or Deflate-compressed stream by auto-detecting
the header.</p>
<h2>Class: zlib.Zlib<span><a class="mark" href="#zlib_class_zlib_zlib" id="zlib_class_zlib_zlib">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<p>Not exported by the <code>zlib</code> module. It is documented here because it is the base
class of the compressor/decompressor classes.</p>
<p>This class inherits from <a href="stream.html#stream_class_stream_transform"><code>stream.Transform</code></a>, allowing <code>zlib</code> objects to be
used in pipes and similar stream operations.</p>
<h3>zlib.bytesRead<span><a class="mark" href="#zlib_zlib_bytesread" id="zlib_zlib_bytesread">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v8.1.0</span><span>Deprecated since: v10.0.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use <a href="#zlib_zlib_byteswritten"><code>zlib.bytesWritten</code></a> instead.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>Deprecated alias for <a href="#zlib_zlib_byteswritten"><code>zlib.bytesWritten</code></a>. This original name was chosen
because it also made sense to interpret the value as the number of bytes
read by the engine, but is inconsistent with other streams in Node.js that
expose values under these names.</p>
<h3>zlib.bytesWritten<span><a class="mark" href="#zlib_zlib_byteswritten" id="zlib_zlib_byteswritten">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v10.0.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>The <code>zlib.bytesWritten</code> property specifies the number of bytes written to
the engine, before the bytes are processed (compressed or decompressed,
as appropriate for the derived class).</p>
<h3>zlib.close([callback])<span><a class="mark" href="#zlib_zlib_close_callback" id="zlib_zlib_close_callback">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.9.4</span>
</div>
<ul>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<p>Close the underlying handle.</p>
<h3>zlib.flush([kind, ]callback)<span><a class="mark" href="#zlib_zlib_flush_kind_callback" id="zlib_zlib_flush_kind_callback">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>kind</code> <strong>Default:</strong> <code>zlib.constants.Z_FULL_FLUSH</code></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<p>Flush pending data. Don't call this frivolously, premature flushes negatively
impact the effectiveness of the compression algorithm.</p>
<p>Calling this only flushes data from the internal <code>zlib</code> state, and does not
perform flushing of any kind on the streams level. Rather, it behaves like a
normal call to <code>.write()</code>, i.e. it will be queued up behind other pending
writes and will only produce output when data is being read from the stream.</p>
<h3>zlib.params(level, strategy, callback)<span><a class="mark" href="#zlib_zlib_params_level_strategy_callback" id="zlib_zlib_params_level_strategy_callback">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.11.4</span>
</div>
<ul>
<li><code>level</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<p>Dynamically update the compression level and compression strategy.
Only applicable to deflate algorithm.</p>
<h3>zlib.reset()<span><a class="mark" href="#zlib_zlib_reset" id="zlib_zlib_reset">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.7.0</span>
</div>
<p>Reset the compressor/decompressor to factory defaults. Only applicable to
the inflate and deflate algorithms.</p>
<h2>zlib.constants<span><a class="mark" href="#zlib_zlib_constants" id="zlib_zlib_constants">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v7.0.0</span>
</div>
<p>Provides an object enumerating Zlib-related constants.</p>
<h2>zlib.createDeflate([options])<span><a class="mark" href="#zlib_zlib_createdeflate_options" id="zlib_zlib_createdeflate_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_deflate"><code>Deflate</code></a> object.</p>
<h2>zlib.createDeflateRaw([options])<span><a class="mark" href="#zlib_zlib_createdeflateraw_options" id="zlib_zlib_createdeflateraw_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_deflateraw"><code>DeflateRaw</code></a> object.</p>
<p>An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when <code>windowBits</code>
is set to 8 for raw deflate streams. zlib would automatically set <code>windowBits</code>
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 <code>windowBits = 9</code> to zlib actually results in a compressed stream
that effectively uses an 8-bit window only.</p>
<h2>zlib.createGunzip([options])<span><a class="mark" href="#zlib_zlib_creategunzip_options" id="zlib_zlib_creategunzip_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_gunzip"><code>Gunzip</code></a> object.</p>
<h2>zlib.createGzip([options])<span><a class="mark" href="#zlib_zlib_creategzip_options" id="zlib_zlib_creategzip_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_gzip"><code>Gzip</code></a> object.</p>
<h2>zlib.createInflate([options])<span><a class="mark" href="#zlib_zlib_createinflate_options" id="zlib_zlib_createinflate_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_inflate"><code>Inflate</code></a> object.</p>
<h2>zlib.createInflateRaw([options])<span><a class="mark" href="#zlib_zlib_createinflateraw_options" id="zlib_zlib_createinflateraw_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_inflateraw"><code>InflateRaw</code></a> object.</p>
<h2>zlib.createUnzip([options])<span><a class="mark" href="#zlib_zlib_createunzip_options" id="zlib_zlib_createunzip_options">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.8</span>
</div>
<ul>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Creates and returns a new <a href="#zlib_class_zlib_unzip"><code>Unzip</code></a> object.</p>
<h2>Convenience Methods<span><a class="mark" href="#zlib_convenience_methods" id="zlib_convenience_methods">#</a></span></h2>
<p>All of these take a <a href="buffer.html#buffer_class_buffer"><code>Buffer</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView"><code>DataView</code></a>,
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a> or string as the first argument, an optional second argument
to supply options to the <code>zlib</code> classes and will call the supplied callback
with <code>callback(error, result)</code>.</p>
<p>Every method has a <code>*Sync</code> counterpart, which accept the same arguments, but
without a callback.</p>
<h3>zlib.deflate(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_deflate_buffer_options_callback" id="zlib_zlib_deflate_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.deflateSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_deflatesync_buffer_options" id="zlib_zlib_deflatesync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Compress a chunk of data with <a href="#zlib_class_zlib_deflate"><code>Deflate</code></a>.</p>
<h3>zlib.deflateRaw(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_deflateraw_buffer_options_callback" id="zlib_zlib_deflateraw_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.deflateRawSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_deflaterawsync_buffer_options" id="zlib_zlib_deflaterawsync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Compress a chunk of data with <a href="#zlib_class_zlib_deflateraw"><code>DeflateRaw</code></a>.</p>
<h3>zlib.gunzip(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_gunzip_buffer_options_callback" id="zlib_zlib_gunzip_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.gunzipSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_gunzipsync_buffer_options" id="zlib_zlib_gunzipsync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Decompress a chunk of data with <a href="#zlib_class_zlib_gunzip"><code>Gunzip</code></a>.</p>
<h3>zlib.gzip(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_gzip_buffer_options_callback" id="zlib_zlib_gzip_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.gzipSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_gzipsync_buffer_options" id="zlib_zlib_gzipsync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Compress a chunk of data with <a href="#zlib_class_zlib_gzip"><code>Gzip</code></a>.</p>
<h3>zlib.inflate(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_inflate_buffer_options_callback" id="zlib_zlib_inflate_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.inflateSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_inflatesync_buffer_options" id="zlib_zlib_inflatesync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Decompress a chunk of data with <a href="#zlib_class_zlib_inflate"><code>Inflate</code></a>.</p>
<h3>zlib.inflateRaw(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_inflateraw_buffer_options_callback" id="zlib_zlib_inflateraw_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.inflateRawSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_inflaterawsync_buffer_options" id="zlib_zlib_inflaterawsync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Decompress a chunk of data with <a href="#zlib_class_zlib_inflateraw"><code>InflateRaw</code></a>.</p>
<h3>zlib.unzip(buffer[, options], callback)<span><a class="mark" href="#zlib_zlib_unzip_buffer_options_callback" id="zlib_zlib_unzip_buffer_options_callback">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.6.0</td>
<td><p><span>Added in: v0.6.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
</ul>
<h3>zlib.unzipSync(buffer[, options])<span><a class="mark" href="#zlib_zlib_unzipsync_buffer_options" id="zlib_zlib_unzipsync_buffer_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.4.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
<tr><td>v0.11.12</td>
<td><p><span>Added in: v0.11.12</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type"><zlib options></a></li>
</ul>
<p>Decompress a chunk of data with <a href="#zlib_class_zlib_unzip"><code>Unzip</code></a>.</p>
</div>
</div>
</div>
<script src="assets/runkit.js"></script>
</body>
</html>