Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 859a02d

Browse files
Renegade334aduh95
authored andcommitted
doc: minor structural stream/iter edits
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63089 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 630b15e commit 859a02d

4 files changed

Lines changed: 265 additions & 268 deletions

File tree

β€Ždoc/api/index.mdβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*[HTTPS](https.md)
3838
*[Inspector](inspector.md)
3939
*[Internationalization](intl.md)
40+
*[Iterable Streams API](stream_iter.md)
4041
*[Modules: CommonJS modules](modules.md)
4142
*[Modules: ECMAScript modules](esm.md)
4243
*[Modules: `node:module` API](module.md)
4344
*[Modules: Packages](packages.md)
4445
*[Modules: TypeScript](typescript.md)
4546
*[Net](net.md)
46-
*[Iterable Streams API](stream_iter.md)
4747
*[OS](os.md)
4848
*[Path](path.md)
4949
*[Performance hooks](perf_hooks.md)
@@ -73,7 +73,6 @@
7373
*[Web Streams API](webstreams.md)
7474
*[Worker threads](worker_threads.md)
7575
*[Zlib](zlib.md)
76-
*[Zlib Iterable Compression](zlib_iter.md)
7776

7877
<hrclass="line"/>
7978

β€Ždoc/api/stream_iter.mdβ€Ž

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ if (writer.endSync() < 0) await writer.end();
416416
writer.fail(err); // Always synchronous, no fallback needed
417417
```
418418

419-
### `writer.desiredSize`
419+
####`writer.desiredSize`
420420

421421
* {number|null}
422422

@@ -425,7 +425,7 @@ Returns `null` if the writer is closed or the consumer has disconnected.
425425

426426
The value is always non-negative.
427427

428-
### `writer.end([options])`
428+
####`writer.end([options])`
429429

430430
*`options` {Object}
431431
*`signal` {AbortSignal} Cancel just this operation. The signal cancels only
@@ -434,7 +434,7 @@ The value is always non-negative.
434434

435435
Signal that no more data will be written.
436436

437-
### `writer.endSync()`
437+
####`writer.endSync()`
438438

439439
* Returns: {number} Total bytes written, or `-1` if the writer is not open.
440440

@@ -448,7 +448,7 @@ if (result < 0) {
448448
}
449449
```
450450

451-
### `writer.fail(reason)`
451+
####`writer.fail(reason)`
452452

453453
*`reason` {any}
454454

@@ -457,7 +457,7 @@ or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is
457457
unconditionally synchronous because failing a writer is a pure state
458458
transition with no async work to perform.
459459

460-
### `writer.write(chunk[, options])`
460+
####`writer.write(chunk[, options])`
461461

462462
*`chunk` {Uint8Array|string}
463463
*`options` {Object}
@@ -467,15 +467,15 @@ transition with no async work to perform.
467467

468468
Write a chunk. The promise resolves when buffer space is available.
469469

470-
### `writer.writeSync(chunk)`
470+
####`writer.writeSync(chunk)`
471471

472472
*`chunk` {Uint8Array|string}
473473
* Returns: {boolean} `true` if the write was accepted, `false` if the
474474
buffer is full.
475475

476476
Synchronous write. Does not block; returns `false` if backpressure is active.
477477

478-
### `writer.writev(chunks[, options])`
478+
####`writer.writev(chunks[, options])`
479479

480480
*`chunks` {Uint8Array\[]|string\[]}
481481
*`options` {Object}
@@ -485,7 +485,7 @@ Synchronous write. Does not block; returns `false` if backpressure is active.
485485

486486
Write multiple chunks as a single batch.
487487

488-
### `writer.writevSync(chunks)`
488+
####`writer.writevSync(chunks)`
489489

490490
*`chunks` {Uint8Array\[]|string\[]}
491491
* Returns: {boolean} `true` if the write was accepted, `false` if the
@@ -1422,7 +1422,7 @@ added: REPLACEME
14221422

14231423
Compression and decompression transforms for use with `pull()`, `pullSync()`,
14241424
`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`][]
1425-
module. See the [`node:zlib/iter` documentation][] for details.
1425+
module. See the [`node:zlib/iter` documentation][`node:zlib/iter`] for details.
14261426

14271427
## Classic stream interop
14281428

@@ -2069,8 +2069,7 @@ console.log(textSync(stream)); // 'hello world'
20692069
[`bytes()`]: #bytessource-options
20702070
[`from()`]: #frominput
20712071
[`fromSync()`]: #fromsyncinput
2072-
[`node:zlib/iter`]: zlib_iter.md
2073-
[`node:zlib/iter` documentation]: zlib_iter.md
2072+
[`node:zlib/iter`]: zlib.md#iterable-compression
20742073
[`pipeTo()`]: #pipetosource-transforms-writer-options
20752074
[`pull()`]: #pullsource-transforms-options
20762075
[`pullSync()`]: #pullsyncsource-transforms-options

β€Ždoc/api/zlib.mdβ€Ž

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,261 @@ added:
17601760

17611761
Decompress a chunk of data with [`ZstdDecompress`][].
17621762

1763+
## Iterable Compression
1764+
1765+
<!-- YAML
1766+
added: v25.9.0
1767+
-->
1768+
1769+
> Stability: 1 - Experimental
1770+
1771+
The `node:zlib/iter` module provides compression and decompression transforms
1772+
for use with the [`node:stream/iter`][] iterable streams API.
1773+
1774+
This module is available only when the `--experimental-stream-iter` CLI flag
1775+
is enabled.
1776+
1777+
Each algorithm has both an async variant (stateful async generator, for use
1778+
with [`pull()`][] and [`pipeTo()`][]) and a sync variant (stateful sync
1779+
generator, for use with `pullSync()` and `pipeToSync()`).
1780+
1781+
The async transforms run compression on the libuv threadpool, overlapping
1782+
I/O with JavaScript execution. The sync transforms run compression directly
1783+
on the main thread.
1784+
1785+
> Note: The defaults for these transforms are tuned for streaming throughput,
1786+
> and differ from the defaults in `node:zlib`. In particular, gzip/deflate
1787+
> default to level 4 (not 6) and memLevel 9 (not 8), and Brotli defaults to
1788+
> quality 6 (not 11). These choices match common HTTP server configurations
1789+
> and provide significantly faster compression with only a small reduction in
1790+
> compression ratio. All defaults can be overridden via options.
1791+
1792+
```mjs
1793+
import { from, pull, bytes, text } from'node:stream/iter';
1794+
import { compressGzip, decompressGzip } from'node:zlib/iter';
1795+
1796+
// Async round-trip
1797+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1798+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1799+
console.log(original); // 'hello'
1800+
```
1801+
1802+
```cjs
1803+
const { from, pull, bytes, text } =require('node:stream/iter');
1804+
const { compressGzip, decompressGzip } =require('node:zlib/iter');
1805+
1806+
asyncfunctionrun() {
1807+
constcompressed=awaitbytes(pull(from('hello'), compressGzip()));
1808+
constoriginal=awaittext(pull(from(compressed), decompressGzip()));
1809+
console.log(original); // 'hello'
1810+
}
1811+
1812+
run().catch(console.error);
1813+
```
1814+
1815+
```mjs
1816+
import { fromSync, pullSync, textSync } from'node:stream/iter';
1817+
import { compressGzipSync, decompressGzipSync } from'node:zlib/iter';
1818+
1819+
// Sync round-trip
1820+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1821+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1822+
console.log(original); // 'hello'
1823+
```
1824+
1825+
```cjs
1826+
const { fromSync, pullSync, textSync } =require('node:stream/iter');
1827+
const { compressGzipSync, decompressGzipSync } =require('node:zlib/iter');
1828+
1829+
constcompressed=pullSync(fromSync('hello'), compressGzipSync());
1830+
constoriginal=textSync(pullSync(compressed, decompressGzipSync()));
1831+
console.log(original); // 'hello'
1832+
```
1833+
1834+
### `compressBrotli([options])`
1835+
1836+
### `compressBrotliSync([options])`
1837+
1838+
<!-- YAML
1839+
added: v25.9.0
1840+
-->
1841+
1842+
*`options` {Object}
1843+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1844+
*`params` {Object} Key-value object where keys and values are
1845+
`zlib.constants` entries. The most important compressor parameters are:
1846+
*`BROTLI_PARAM_MODE` -- `BROTLI_MODE_GENERIC` (default),
1847+
`BROTLI_MODE_TEXT`, or `BROTLI_MODE_FONT`.
1848+
*`BROTLI_PARAM_QUALITY` -- ranges from `BROTLI_MIN_QUALITY` to
1849+
`BROTLI_MAX_QUALITY`. **Default:**`6` (not `BROTLI_DEFAULT_QUALITY`
1850+
which is 11). Quality 6 is appropriate for streaming; quality 11 is
1851+
intended for offline/build-time compression.
1852+
*`BROTLI_PARAM_SIZE_HINT` -- expected input size. **Default:**`0`
1853+
(unknown).
1854+
*`BROTLI_PARAM_LGWIN` -- window size (log2). **Default:**`20` (1 MB).
1855+
The Brotli library default is 22 (4 MB); the reduced default saves
1856+
memory without significant compression impact for streaming workloads.
1857+
*`BROTLI_PARAM_LGBLOCK` -- input block size (log2).
1858+
See the [Brotli compressor options][] in the zlib documentation for the
1859+
full list.
1860+
*`dictionary` {Buffer|TypedArray|DataView}
1861+
* Returns: {Object} A stateful transform.
1862+
1863+
Create a Brotli compression transform. Output is compatible with
1864+
`zlib.brotliDecompress()` and `decompressBrotli()`/`decompressBrotliSync()`.
1865+
1866+
### `compressDeflate([options])`
1867+
1868+
### `compressDeflateSync([options])`
1869+
1870+
<!-- YAML
1871+
added: v25.9.0
1872+
-->
1873+
1874+
*`options` {Object}
1875+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1876+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1877+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1878+
*`memLevel` {number} **Default:**`9`.
1879+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1880+
*`dictionary` {Buffer|TypedArray|DataView}
1881+
* Returns: {Object} A stateful transform.
1882+
1883+
Create a deflate compression transform. Output is compatible with
1884+
`zlib.inflate()` and `decompressDeflate()`/`decompressDeflateSync()`.
1885+
1886+
### `compressGzip([options])`
1887+
1888+
### `compressGzipSync([options])`
1889+
1890+
<!-- YAML
1891+
added: v25.9.0
1892+
-->
1893+
1894+
*`options` {Object}
1895+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1896+
*`level` {number} Compression level (`0`-`9`). **Default:**`4`.
1897+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1898+
*`memLevel` {number} **Default:**`9`.
1899+
*`strategy` {number} **Default:**`Z_DEFAULT_STRATEGY`.
1900+
*`dictionary` {Buffer|TypedArray|DataView}
1901+
* Returns: {Object} A stateful transform.
1902+
1903+
Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
1904+
and `decompressGzip()`/`decompressGzipSync()`.
1905+
1906+
### `compressZstd([options])`
1907+
1908+
### `compressZstdSync([options])`
1909+
1910+
<!-- YAML
1911+
added: v25.9.0
1912+
-->
1913+
1914+
*`options` {Object}
1915+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1916+
*`params` {Object} Key-value object where keys and values are
1917+
`zlib.constants` entries. The most important compressor parameters are:
1918+
*`ZSTD_c_compressionLevel` -- **Default:**`ZSTD_CLEVEL_DEFAULT` (3).
1919+
*`ZSTD_c_checksumFlag` -- generate a checksum. **Default:**`0`.
1920+
*`ZSTD_c_strategy` -- compression strategy. Values include
1921+
`ZSTD_fast`, `ZSTD_dfast`, `ZSTD_greedy`, `ZSTD_lazy`,
1922+
`ZSTD_lazy2`, `ZSTD_btlazy2`, `ZSTD_btopt`, `ZSTD_btultra`,
1923+
`ZSTD_btultra2`.
1924+
See the [Zstd compressor options][] in the zlib documentation for the
1925+
full list.
1926+
*`pledgedSrcSize` {number} Expected uncompressed size (optional hint).
1927+
*`dictionary` {Buffer|TypedArray|DataView}
1928+
* Returns: {Object} A stateful transform.
1929+
1930+
Create a Zstandard compression transform. Output is compatible with
1931+
`zlib.zstdDecompress()` and `decompressZstd()`/`decompressZstdSync()`.
1932+
1933+
### `decompressBrotli([options])`
1934+
1935+
### `decompressBrotliSync([options])`
1936+
1937+
<!-- YAML
1938+
added: v25.9.0
1939+
-->
1940+
1941+
*`options` {Object}
1942+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1943+
*`params` {Object} Key-value object where keys and values are
1944+
`zlib.constants` entries. Available decompressor parameters:
1945+
*`BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION` -- boolean
1946+
flag affecting internal memory allocation.
1947+
*`BROTLI_DECODER_PARAM_LARGE_WINDOW` -- boolean flag enabling "Large
1948+
Window Brotli" mode (not compatible with [RFC 7932][]).
1949+
See the [Brotli decompressor options][] in the zlib documentation for
1950+
details.
1951+
*`dictionary` {Buffer|TypedArray|DataView}
1952+
* Returns: {Object} A stateful transform.
1953+
1954+
Create a Brotli decompression transform.
1955+
1956+
### `decompressDeflate([options])`
1957+
1958+
### `decompressDeflateSync([options])`
1959+
1960+
<!-- YAML
1961+
added: v25.9.0
1962+
-->
1963+
1964+
*`options` {Object}
1965+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1966+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1967+
*`dictionary` {Buffer|TypedArray|DataView}
1968+
* Returns: {Object} A stateful transform.
1969+
1970+
Create a deflate decompression transform.
1971+
1972+
### `decompressGzip([options])`
1973+
1974+
### `decompressGzipSync([options])`
1975+
1976+
<!-- YAML
1977+
added: v25.9.0
1978+
-->
1979+
1980+
*`options` {Object}
1981+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1982+
*`windowBits` {number} **Default:**`Z_DEFAULT_WINDOWBITS` (15).
1983+
*`dictionary` {Buffer|TypedArray|DataView}
1984+
* Returns: {Object} A stateful transform.
1985+
1986+
Create a gzip decompression transform.
1987+
1988+
### `decompressZstd([options])`
1989+
1990+
### `decompressZstdSync([options])`
1991+
1992+
<!-- YAML
1993+
added: v25.9.0
1994+
-->
1995+
1996+
*`options` {Object}
1997+
*`chunkSize` {number} Output buffer size. **Default:**`65536` (64 KB).
1998+
*`params` {Object} Key-value object where keys and values are
1999+
`zlib.constants` entries. Available decompressor parameters:
2000+
*`ZSTD_d_windowLogMax` -- maximum window size (log2) the decompressor
2001+
will allocate. Limits memory usage against malicious input.
2002+
See the [Zstd decompressor options][] in the zlib documentation for
2003+
details.
2004+
*`dictionary` {Buffer|TypedArray|DataView}
2005+
* Returns: {Object} A stateful transform.
2006+
2007+
Create a Zstandard decompression transform.
2008+
2009+
[Brotli compressor options]: #compressor-options
2010+
[Brotli decompressor options]: #decompressor-options
17632011
[Brotli parameters]: #brotli-constants
17642012
[Cyclic redundancy check]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
17652013
[Memory usage tuning]: #memory-usage-tuning
1766-
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
2014+
[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.html
17672015
[Streams API]: stream.md
2016+
[Zstd compressor options]: #compressor-options
2017+
[Zstd decompressor options]: #decompressor-options
17682018
[Zstd parameters]: #zstd-constants
17692019
[`.flush()`]: #zlibflushkind-callback
17702020
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
@@ -1783,6 +2033,9 @@ Decompress a chunk of data with [`ZstdDecompress`][].
17832033
[`ZstdDecompress`]: #class-zlibzstddecompress
17842034
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
17852035
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
2036+
[`node:stream/iter`]: stream_iter.md
2037+
[`pipeTo()`]: stream_iter.md#pipetosource-transforms-writer-options
2038+
[`pull()`]: stream_iter.md#pullsource-transforms-options
17862039
[`stream.Transform`]: stream.md#class-streamtransform
17872040
[convenience methods]: #convenience-methods
17882041
[zlib documentation]: https://zlib.net/manual.html#Constants

0 commit comments

Comments
Β (0)