@@ -2564,6 +2564,119 @@ added: v0.5.8
25642564
25652565Creates and returns a new [ ` Unzip ` ] [ ] object.
25662566
2567+ ## Synchronous incremental codecs
2568+
2569+ <!-- YAML
2570+ added: v28.0.0
2571+ -->
2572+
2573+ The synchronous incremental codecs decompress (or compress) data incrementally
2574+ into buffers the caller provides. They are an alternative to the streaming
2575+ classes and the one-shot synchronous convenience methods:
2576+
2577+ * The streaming classes (` zlib.createGunzip() ` , and so on) run every chunk
2578+ through the thread pool, allocate a new output buffer for every chunk, and add
2579+ the ` Transform ` overhead.
2580+ * The one-shot synchronous methods (` zlib.gunzipSync() ` , and so on) need the
2581+ whole input in memory and return the whole output as one buffer.
2582+
2583+ The codecs let a caller own the output buffer, so it can be reused, pooled, or
2584+ aligned. There is no thread pool hop and no stream machinery, which makes them a
2585+ good fit for parsers that consume decompressed data right away (for example, a
2586+ tar parser).
2587+
2588+ These classes are available:
2589+
2590+ * [ ` zlib.DeflateSync ` ] [ ] , [ ` zlib.InflateSync ` ] [ ]
2591+ * [ ` zlib.GzipSync ` ] [ ] , [ ` zlib.GunzipSync ` ] [ ]
2592+ * [ ` zlib.DeflateRawSync ` ] [ ] , [ ` zlib.InflateRawSync ` ] [ ]
2593+ * [ ` zlib.UnzipSync ` ] [ ]
2594+ * [ ` zlib.BrotliCompressSync ` ] [ ] , [ ` zlib.BrotliDecompressSync ` ] [ ]
2595+ * [ ` zlib.ZstdCompressSync ` ] [ ] , [ ` zlib.ZstdDecompressSync ` ] [ ]
2596+
2597+ The ` zlib.create*Sync() ` functions create the corresponding codec, and each
2598+ codec exposes [ ` codec.process() ` ] [ ] , [ ` codec.end() ` ] [ ] , [ ` codec.reset() ` ] [ ] , and
2599+ [ ` codec.close() ` ] [ ] methods.
2600+
2601+ ### ` zlib.createDeflateSync([options]) ` , ` zlib.createInflateSync([options]) ` , and so on
2602+
2603+ <!-- YAML
2604+ added: v28.0.0
2605+ -->
2606+
2607+ * ` options ` {zlib options}
2608+
2609+ Creates and returns a new synchronous incremental codec for the algorithm the
2610+ factory is named after. The available factories are ` createDeflateSync ` ,
2611+ ` createInflateSync ` , ` createGzipSync ` , ` createGunzipSync ` ,
2612+ ` createDeflateRawSync ` , ` createInflateRawSync ` , ` createUnzipSync ` ,
2613+ ` createBrotliCompressSync ` , ` createBrotliDecompressSync ` ,
2614+ ` createZstdCompressSync ` , and ` createZstdDecompressSync ` .
2615+
2616+ ### ` codec.process(input, output[, options]) `
2617+
2618+ <!-- YAML
2619+ added: v28.0.0
2620+ -->
2621+
2622+ * ` input ` {Buffer|TypedArray|DataView|ArrayBuffer|string} The data to process.
2623+ * ` output ` {Buffer|TypedArray|DataView|ArrayBuffer} A buffer to write into.
2624+ * ` options ` {Object}
2625+ * ` flush ` {integer} The flush flag. Defaults to the algorithm default
2626+ (` Z_NO_FLUSH ` , ` BROTLI_OPERATION_PROCESS ` , or ` ZSTD_e_continue ` ).
2627+ * ` offset ` {integer} The byte offset into ` output ` at which to start writing.
2628+ Default: ` 0 ` . This lets a caller append output into a shared, pooled buffer
2629+ across calls instead of handing in a fresh buffer each time.
2630+ * Returns: {Object} An object with ` bytesRead ` , ` bytesWritten ` , and ` finished `
2631+ properties.
2632+
2633+ Processes ` input ` , writing as much output as fits in ` output ` (starting at
2634+ ` options.offset ` ). The returned ` bytesRead ` is how many input bytes were
2635+ consumed and ` bytesWritten ` is how many bytes were written to ` output ` . When
2636+ ` bytesWritten ` equals ` output.byteLength - offset ` , the output buffer is full
2637+ and the caller should call ` process() ` again with the remaining input and a
2638+ fresh output buffer (or a new ` offset ` ). ` finished ` is ` true ` once the end of
2639+ the compressed stream (or frame) has been reached.
2640+
2641+ ### ` codec.end(output) `
2642+
2643+ <!-- YAML
2644+ added: v28.0.0
2645+ -->
2646+
2647+ * ` output ` {Buffer|TypedArray|DataView|ArrayBuffer} A buffer to write into.
2648+ * ` options ` {Object}
2649+ * ` offset ` {integer} The byte offset into ` output ` at which to start writing.
2650+ Default: ` 0 ` .
2651+ * Returns: {Object} An object with ` bytesWritten ` and ` finished ` properties.
2652+
2653+ Performs the final flush (the finish flush) with no new input, writing any
2654+ remaining output into ` output ` . After ` end() ` returns with ` finished ` set to
2655+ ` true ` , the codec cannot process further input; calling ` process() ` again throws
2656+ an ` ERR_STREAM_WRITE_AFTER_END ` error. If a truncated stream is fed, ` end() `
2657+ throws (for example, an ` unexpected end of file ` error).
2658+
2659+ ### ` codec.reset() `
2660+
2661+ <!-- YAML
2662+ added: v28.0.0
2663+ -->
2664+
2665+ * Returns: {Object} Returns the codec, so it can be reused for a new stream.
2666+
2667+ Resets the underlying stream so the codec can be reused. This avoids the cost of
2668+ creating a new codec for every archive.
2669+
2670+ ### ` codec.close() `
2671+
2672+ <!-- YAML
2673+ added: v28.0.0
2674+ -->
2675+
2676+ Closes the codec and frees its underlying native handle. After calling
2677+ ` close() ` , any further ` process() ` or ` end() ` call throws an
2678+ ` ERR_STREAM_PREMATURE_CLOSE ` error.
2679+
25672680## ` zlib.createZipArchive(entries[, options]) `
25682681
25692682<!-- YAML
@@ -3611,6 +3724,23 @@ Create a Zstandard decompression transform.
36113724[ `zlib.ZipEntry.createSync()` ] : #static-method-zlibzipentrycreatesyncfilename-data-options
36123725[ `zlib.ZipFile.open()` ] : #static-method-zlibzipfileopenfilename-options
36133726[ `zlib.crc32()` ] : #zlibcrc32data-value
3727+ [ `zlib.createDeflateSync` ] : #synchronous-incremental-codecs
3728+ [ `zlib.createGunzipSync` ] : #synchronous-incremental-codecs
3729+ [ `zlib.BrotliCompressSync` ] : #synchronous-incremental-codecs
3730+ [ `zlib.BrotliDecompressSync` ] : #synchronous-incremental-codecs
3731+ [ `zlib.DeflateRawSync` ] : #synchronous-incremental-codecs
3732+ [ `zlib.DeflateSync` ] : #synchronous-incremental-codecs
3733+ [ `zlib.GunzipSync` ] : #synchronous-incremental-codecs
3734+ [ `zlib.GzipSync` ] : #synchronous-incremental-codecs
3735+ [ `zlib.InflateRawSync` ] : #synchronous-incremental-codecs
3736+ [ `zlib.InflateSync` ] : #synchronous-incremental-codecs
3737+ [ `zlib.UnzipSync` ] : #synchronous-incremental-codecs
3738+ [ `zlib.ZstdCompressSync` ] : #synchronous-incremental-codecs
3739+ [ `zlib.ZstdDecompressSync` ] : #synchronous-incremental-codecs
3740+ [ `codec.process()` ] : #codecprocessinput-output-options
3741+ [ `codec.end()` ] : #codecendoutput
3742+ [ `codec.reset()` ] : #codecreset
3743+ [ `codec.close()` ] : #codecclose
36143744[ `zlib.createZipArchive()` ] : #zlibcreateziparchiveentries-options
36153745[ `zlib.createZipArchiveSync()` ] : #zlibcreateziparchivesyncentries-options
36163746[ `zlib.getMaxZipContentSize()` ] : #zlibgetmaxzipcontentsize
0 commit comments