cdk-ecr-deployment 2.5.6 → 2.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +5 -4
- package/.jsii +673 -21
- package/.jsii.tabl.json +1 -0
- package/.projenrc.ts +100 -0
- package/API.md +4 -4
- package/README.md +4 -4
- package/lambda/go.mod +2 -5
- package/lambda/go.sum +39 -14
- package/lib/index.d.ts +7 -65
- package/lib/index.js +7 -45
- package/node_modules/@sindresorhus/is/dist/index.d.ts +12 -7
- package/node_modules/@sindresorhus/is/dist/index.js +9 -4
- package/node_modules/@sindresorhus/is/dist/types.d.ts +1 -0
- package/node_modules/@sindresorhus/is/package.json +1 -1
- package/node_modules/@sindresorhus/is/readme.md +25 -7
- package/node_modules/@types/cacheable-request/README.md +2 -2
- package/node_modules/@types/cacheable-request/node_modules/@types/node/README.md +2 -2
- package/node_modules/@types/cacheable-request/node_modules/@types/node/assert.d.ts +135 -75
- package/node_modules/@types/cacheable-request/node_modules/@types/node/async_hooks.d.ts +67 -38
- package/node_modules/@types/cacheable-request/node_modules/@types/node/buffer.d.ts +226 -104
- package/node_modules/@types/cacheable-request/node_modules/@types/node/child_process.d.ts +87 -58
- package/node_modules/@types/cacheable-request/node_modules/@types/node/cluster.d.ts +29 -29
- package/node_modules/@types/cacheable-request/node_modules/@types/node/console.d.ts +5 -5
- package/node_modules/@types/cacheable-request/node_modules/@types/node/crypto.d.ts +888 -256
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dgram.d.ts +16 -16
- package/node_modules/@types/cacheable-request/node_modules/@types/node/diagnostics_channel.d.ts +60 -21
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns/promises.d.ts +52 -8
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns.d.ts +27 -18
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dom-events.d.ts +126 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/domain.d.ts +6 -5
- package/node_modules/@types/cacheable-request/node_modules/@types/node/events.d.ts +166 -93
- package/node_modules/@types/cacheable-request/node_modules/@types/node/fs/promises.d.ts +169 -70
- package/node_modules/@types/cacheable-request/node_modules/@types/node/fs.d.ts +301 -126
- package/node_modules/@types/cacheable-request/node_modules/@types/node/globals.d.ts +22 -13
- package/node_modules/@types/cacheable-request/node_modules/@types/node/http.d.ts +453 -125
- package/node_modules/@types/cacheable-request/node_modules/@types/node/http2.d.ts +74 -46
- package/node_modules/@types/cacheable-request/node_modules/@types/node/https.d.ts +103 -53
- package/node_modules/@types/cacheable-request/node_modules/@types/node/index.d.ts +6 -2
- package/node_modules/@types/cacheable-request/node_modules/@types/node/inspector.d.ts +20 -16
- package/node_modules/@types/cacheable-request/node_modules/@types/node/module.d.ts +6 -4
- package/node_modules/@types/cacheable-request/node_modules/@types/node/net.d.ts +114 -22
- package/node_modules/@types/cacheable-request/node_modules/@types/node/os.d.ts +36 -14
- package/node_modules/@types/cacheable-request/node_modules/@types/node/package.json +15 -3
- package/node_modules/@types/cacheable-request/node_modules/@types/node/path.d.ts +37 -26
- package/node_modules/@types/cacheable-request/node_modules/@types/node/perf_hooks.d.ts +96 -15
- package/node_modules/@types/cacheable-request/node_modules/@types/node/process.d.ts +95 -82
- package/node_modules/@types/cacheable-request/node_modules/@types/node/punycode.d.ts +1 -1
- package/node_modules/@types/cacheable-request/node_modules/@types/node/querystring.d.ts +6 -6
- package/node_modules/@types/cacheable-request/node_modules/@types/node/readline/promises.d.ts +145 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/readline.d.ts +51 -175
- package/node_modules/@types/cacheable-request/node_modules/@types/node/repl.d.ts +21 -21
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/consumers.d.ts +2 -14
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream.d.ts +983 -824
- package/node_modules/@types/cacheable-request/node_modules/@types/node/string_decoder.d.ts +6 -6
- package/node_modules/@types/cacheable-request/node_modules/@types/node/test.d.ts +1154 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/timers/promises.d.ts +26 -1
- package/node_modules/@types/cacheable-request/node_modules/@types/node/timers.d.ts +127 -6
- package/node_modules/@types/cacheable-request/node_modules/@types/node/tls.d.ts +149 -50
- package/node_modules/@types/cacheable-request/node_modules/@types/node/trace_events.d.ts +30 -9
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/assert.d.ts +972 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/async_hooks.d.ts +530 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/buffer.d.ts +2354 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/child_process.d.ts +1395 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/cluster.d.ts +414 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/crypto.d.ts +3969 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +191 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/dns/promises.d.ts +414 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/dns.d.ts +668 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/events.d.ts +724 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/fs/promises.d.ts +1189 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/fs.d.ts +4044 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/globals.d.ts +303 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/http.d.ts +1724 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/http2.d.ts +2129 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/https.d.ts +441 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/inspector.d.ts +2748 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/module.d.ts +116 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/net.d.ts +888 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/os.d.ts +477 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/perf_hooks.d.ts +638 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/process.d.ts +1494 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/readline/promises.d.ts +145 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/readline.d.ts +526 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/stream.d.ts +1392 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/test.d.ts +1154 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/timers.d.ts +215 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/tls.d.ts +1119 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/trace_events.d.ts +182 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/tty.d.ts +208 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/url.d.ts +901 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/util.d.ts +2052 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/v8.d.ts +635 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/vm.d.ts +894 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/wasi.d.ts +152 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/worker_threads.d.ts +693 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/tty.d.ts +11 -7
- package/node_modules/@types/cacheable-request/node_modules/@types/node/url.d.ts +66 -56
- package/node_modules/@types/cacheable-request/node_modules/@types/node/util.d.ts +528 -70
- package/node_modules/@types/cacheable-request/node_modules/@types/node/v8.d.ts +271 -14
- package/node_modules/@types/cacheable-request/node_modules/@types/node/vm.d.ts +421 -34
- package/node_modules/@types/cacheable-request/node_modules/@types/node/wasi.d.ts +15 -21
- package/node_modules/@types/cacheable-request/node_modules/@types/node/worker_threads.d.ts +81 -37
- package/node_modules/@types/cacheable-request/node_modules/@types/node/zlib.d.ts +11 -11
- package/node_modules/@types/cacheable-request/package.json +5 -5
- package/node_modules/@types/keyv/README.md +1 -1
- package/node_modules/@types/keyv/index.d.ts +16 -3
- package/node_modules/@types/keyv/node_modules/@types/node/README.md +2 -2
- package/node_modules/@types/keyv/node_modules/@types/node/assert.d.ts +135 -75
- package/node_modules/@types/keyv/node_modules/@types/node/async_hooks.d.ts +67 -38
- package/node_modules/@types/keyv/node_modules/@types/node/buffer.d.ts +226 -104
- package/node_modules/@types/keyv/node_modules/@types/node/child_process.d.ts +87 -58
- package/node_modules/@types/keyv/node_modules/@types/node/cluster.d.ts +29 -29
- package/node_modules/@types/keyv/node_modules/@types/node/console.d.ts +5 -5
- package/node_modules/@types/keyv/node_modules/@types/node/crypto.d.ts +888 -256
- package/node_modules/@types/keyv/node_modules/@types/node/dgram.d.ts +16 -16
- package/node_modules/@types/keyv/node_modules/@types/node/diagnostics_channel.d.ts +60 -21
- package/node_modules/@types/keyv/node_modules/@types/node/dns/promises.d.ts +52 -8
- package/node_modules/@types/keyv/node_modules/@types/node/dns.d.ts +27 -18
- package/node_modules/@types/keyv/node_modules/@types/node/dom-events.d.ts +126 -0
- package/node_modules/@types/keyv/node_modules/@types/node/domain.d.ts +6 -5
- package/node_modules/@types/keyv/node_modules/@types/node/events.d.ts +166 -93
- package/node_modules/@types/keyv/node_modules/@types/node/fs/promises.d.ts +169 -70
- package/node_modules/@types/keyv/node_modules/@types/node/fs.d.ts +301 -126
- package/node_modules/@types/keyv/node_modules/@types/node/globals.d.ts +22 -13
- package/node_modules/@types/keyv/node_modules/@types/node/http.d.ts +453 -125
- package/node_modules/@types/keyv/node_modules/@types/node/http2.d.ts +74 -46
- package/node_modules/@types/keyv/node_modules/@types/node/https.d.ts +103 -53
- package/node_modules/@types/keyv/node_modules/@types/node/index.d.ts +6 -2
- package/node_modules/@types/keyv/node_modules/@types/node/inspector.d.ts +20 -16
- package/node_modules/@types/keyv/node_modules/@types/node/module.d.ts +6 -4
- package/node_modules/@types/keyv/node_modules/@types/node/net.d.ts +114 -22
- package/node_modules/@types/keyv/node_modules/@types/node/os.d.ts +36 -14
- package/node_modules/@types/keyv/node_modules/@types/node/package.json +15 -3
- package/node_modules/@types/keyv/node_modules/@types/node/path.d.ts +37 -26
- package/node_modules/@types/keyv/node_modules/@types/node/perf_hooks.d.ts +96 -15
- package/node_modules/@types/keyv/node_modules/@types/node/process.d.ts +95 -82
- package/node_modules/@types/keyv/node_modules/@types/node/punycode.d.ts +1 -1
- package/node_modules/@types/keyv/node_modules/@types/node/querystring.d.ts +6 -6
- package/node_modules/@types/keyv/node_modules/@types/node/readline/promises.d.ts +145 -0
- package/node_modules/@types/keyv/node_modules/@types/node/readline.d.ts +51 -175
- package/node_modules/@types/keyv/node_modules/@types/node/repl.d.ts +21 -21
- package/node_modules/@types/keyv/node_modules/@types/node/stream/consumers.d.ts +2 -14
- package/node_modules/@types/keyv/node_modules/@types/node/stream.d.ts +983 -824
- package/node_modules/@types/keyv/node_modules/@types/node/string_decoder.d.ts +6 -6
- package/node_modules/@types/keyv/node_modules/@types/node/test.d.ts +1154 -0
- package/node_modules/@types/keyv/node_modules/@types/node/timers/promises.d.ts +26 -1
- package/node_modules/@types/keyv/node_modules/@types/node/timers.d.ts +127 -6
- package/node_modules/@types/keyv/node_modules/@types/node/tls.d.ts +149 -50
- package/node_modules/@types/keyv/node_modules/@types/node/trace_events.d.ts +30 -9
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/assert.d.ts +972 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/async_hooks.d.ts +530 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/buffer.d.ts +2354 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/child_process.d.ts +1395 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/cluster.d.ts +414 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/crypto.d.ts +3969 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +191 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/dns/promises.d.ts +414 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/dns.d.ts +668 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/events.d.ts +724 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/fs/promises.d.ts +1189 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/fs.d.ts +4044 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/globals.d.ts +303 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/http.d.ts +1724 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/http2.d.ts +2129 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/https.d.ts +441 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/inspector.d.ts +2748 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/module.d.ts +116 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/net.d.ts +888 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/os.d.ts +477 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/perf_hooks.d.ts +638 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/process.d.ts +1494 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/readline/promises.d.ts +145 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/readline.d.ts +526 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/stream.d.ts +1392 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/test.d.ts +1154 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/timers.d.ts +215 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/tls.d.ts +1119 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/trace_events.d.ts +182 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/tty.d.ts +208 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/url.d.ts +901 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/util.d.ts +2052 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/v8.d.ts +635 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/vm.d.ts +894 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/wasi.d.ts +152 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/worker_threads.d.ts +693 -0
- package/node_modules/@types/keyv/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/node_modules/@types/keyv/node_modules/@types/node/tty.d.ts +11 -7
- package/node_modules/@types/keyv/node_modules/@types/node/url.d.ts +66 -56
- package/node_modules/@types/keyv/node_modules/@types/node/util.d.ts +528 -70
- package/node_modules/@types/keyv/node_modules/@types/node/v8.d.ts +271 -14
- package/node_modules/@types/keyv/node_modules/@types/node/vm.d.ts +421 -34
- package/node_modules/@types/keyv/node_modules/@types/node/wasi.d.ts +15 -21
- package/node_modules/@types/keyv/node_modules/@types/node/worker_threads.d.ts +81 -37
- package/node_modules/@types/keyv/node_modules/@types/node/zlib.d.ts +11 -11
- package/node_modules/@types/keyv/package.json +3 -3
- package/node_modules/@types/responselike/node_modules/@types/node/README.md +2 -2
- package/node_modules/@types/responselike/node_modules/@types/node/assert.d.ts +135 -75
- package/node_modules/@types/responselike/node_modules/@types/node/async_hooks.d.ts +67 -38
- package/node_modules/@types/responselike/node_modules/@types/node/buffer.d.ts +226 -104
- package/node_modules/@types/responselike/node_modules/@types/node/child_process.d.ts +87 -58
- package/node_modules/@types/responselike/node_modules/@types/node/cluster.d.ts +29 -29
- package/node_modules/@types/responselike/node_modules/@types/node/console.d.ts +5 -5
- package/node_modules/@types/responselike/node_modules/@types/node/crypto.d.ts +888 -256
- package/node_modules/@types/responselike/node_modules/@types/node/dgram.d.ts +16 -16
- package/node_modules/@types/responselike/node_modules/@types/node/diagnostics_channel.d.ts +60 -21
- package/node_modules/@types/responselike/node_modules/@types/node/dns/promises.d.ts +52 -8
- package/node_modules/@types/responselike/node_modules/@types/node/dns.d.ts +27 -18
- package/node_modules/@types/responselike/node_modules/@types/node/dom-events.d.ts +126 -0
- package/node_modules/@types/responselike/node_modules/@types/node/domain.d.ts +6 -5
- package/node_modules/@types/responselike/node_modules/@types/node/events.d.ts +166 -93
- package/node_modules/@types/responselike/node_modules/@types/node/fs/promises.d.ts +169 -70
- package/node_modules/@types/responselike/node_modules/@types/node/fs.d.ts +301 -126
- package/node_modules/@types/responselike/node_modules/@types/node/globals.d.ts +22 -13
- package/node_modules/@types/responselike/node_modules/@types/node/http.d.ts +453 -125
- package/node_modules/@types/responselike/node_modules/@types/node/http2.d.ts +74 -46
- package/node_modules/@types/responselike/node_modules/@types/node/https.d.ts +103 -53
- package/node_modules/@types/responselike/node_modules/@types/node/index.d.ts +6 -2
- package/node_modules/@types/responselike/node_modules/@types/node/inspector.d.ts +20 -16
- package/node_modules/@types/responselike/node_modules/@types/node/module.d.ts +6 -4
- package/node_modules/@types/responselike/node_modules/@types/node/net.d.ts +114 -22
- package/node_modules/@types/responselike/node_modules/@types/node/os.d.ts +36 -14
- package/node_modules/@types/responselike/node_modules/@types/node/package.json +15 -3
- package/node_modules/@types/responselike/node_modules/@types/node/path.d.ts +37 -26
- package/node_modules/@types/responselike/node_modules/@types/node/perf_hooks.d.ts +96 -15
- package/node_modules/@types/responselike/node_modules/@types/node/process.d.ts +95 -82
- package/node_modules/@types/responselike/node_modules/@types/node/punycode.d.ts +1 -1
- package/node_modules/@types/responselike/node_modules/@types/node/querystring.d.ts +6 -6
- package/node_modules/@types/responselike/node_modules/@types/node/readline/promises.d.ts +145 -0
- package/node_modules/@types/responselike/node_modules/@types/node/readline.d.ts +51 -175
- package/node_modules/@types/responselike/node_modules/@types/node/repl.d.ts +21 -21
- package/node_modules/@types/responselike/node_modules/@types/node/stream/consumers.d.ts +2 -14
- package/node_modules/@types/responselike/node_modules/@types/node/stream.d.ts +983 -824
- package/node_modules/@types/responselike/node_modules/@types/node/string_decoder.d.ts +6 -6
- package/node_modules/@types/responselike/node_modules/@types/node/test.d.ts +1154 -0
- package/node_modules/@types/responselike/node_modules/@types/node/timers/promises.d.ts +26 -1
- package/node_modules/@types/responselike/node_modules/@types/node/timers.d.ts +127 -6
- package/node_modules/@types/responselike/node_modules/@types/node/tls.d.ts +149 -50
- package/node_modules/@types/responselike/node_modules/@types/node/trace_events.d.ts +30 -9
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/assert.d.ts +972 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/async_hooks.d.ts +530 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/buffer.d.ts +2354 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/child_process.d.ts +1395 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/cluster.d.ts +414 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/crypto.d.ts +3969 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +191 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/dns/promises.d.ts +414 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/dns.d.ts +668 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/events.d.ts +724 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/fs/promises.d.ts +1189 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/fs.d.ts +4044 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/globals.d.ts +303 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/http.d.ts +1724 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/http2.d.ts +2129 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/https.d.ts +441 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/inspector.d.ts +2748 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/module.d.ts +116 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/net.d.ts +888 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/os.d.ts +477 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/perf_hooks.d.ts +638 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/process.d.ts +1494 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/readline/promises.d.ts +145 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/readline.d.ts +526 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/stream.d.ts +1392 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/test.d.ts +1154 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/timers.d.ts +215 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/tls.d.ts +1119 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/trace_events.d.ts +182 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/tty.d.ts +208 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/url.d.ts +901 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/util.d.ts +2052 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/v8.d.ts +635 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/vm.d.ts +894 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/wasi.d.ts +152 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/worker_threads.d.ts +693 -0
- package/node_modules/@types/responselike/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/node_modules/@types/responselike/node_modules/@types/node/tty.d.ts +11 -7
- package/node_modules/@types/responselike/node_modules/@types/node/url.d.ts +66 -56
- package/node_modules/@types/responselike/node_modules/@types/node/util.d.ts +528 -70
- package/node_modules/@types/responselike/node_modules/@types/node/v8.d.ts +271 -14
- package/node_modules/@types/responselike/node_modules/@types/node/vm.d.ts +421 -34
- package/node_modules/@types/responselike/node_modules/@types/node/wasi.d.ts +15 -21
- package/node_modules/@types/responselike/node_modules/@types/node/worker_threads.d.ts +81 -37
- package/node_modules/@types/responselike/node_modules/@types/node/zlib.d.ts +11 -11
- package/node_modules/cacheable-request/package.json +1 -1
- package/node_modules/clone-response/node_modules/mimic-response/index.js +32 -0
- package/node_modules/{get-stream → clone-response/node_modules/mimic-response}/license +1 -1
- package/node_modules/clone-response/node_modules/mimic-response/package.json +37 -0
- package/node_modules/clone-response/node_modules/mimic-response/readme.md +54 -0
- package/node_modules/clone-response/package.json +3 -6
- package/node_modules/got/dist/source/as-promise/index.js +1 -0
- package/node_modules/got/package.json +2 -1
- package/node_modules/http-cache-semantics/index.js +4 -3
- package/node_modules/http-cache-semantics/package.json +2 -8
- package/node_modules/keyv/README.md +141 -5
- package/node_modules/keyv/package.json +56 -50
- package/node_modules/keyv/src/index.d.ts +116 -0
- package/node_modules/keyv/src/index.js +179 -24
- package/node_modules/mimic-response/index.js +58 -13
- package/node_modules/mimic-response/license +1 -1
- package/node_modules/mimic-response/package.json +40 -35
- package/node_modules/mimic-response/readme.md +33 -9
- package/node_modules/responselike/package.json +3 -2
- package/package.json +54 -25
- package/rosetta/default.ts-fixture +17 -0
- package/changelog.md +0 -2
- package/node_modules/decompress-response/node_modules/mimic-response/index.js +0 -77
- package/node_modules/decompress-response/node_modules/mimic-response/package.json +0 -42
- package/node_modules/decompress-response/node_modules/mimic-response/readme.md +0 -78
- package/node_modules/keyv/.nyc_output/37411020-4142-4b08-b825-343ba2427bf7.json +0 -1
- package/node_modules/keyv/.nyc_output/cd79f2de-c8b8-4493-bc15-b2bde28efa4b.json +0 -1
- package/node_modules/keyv/.nyc_output/processinfo/37411020-4142-4b08-b825-343ba2427bf7.json +0 -1
- package/node_modules/keyv/.nyc_output/processinfo/cd79f2de-c8b8-4493-bc15-b2bde28efa4b.json +0 -1
- package/node_modules/keyv/.nyc_output/processinfo/index.json +0 -1
- package/node_modules/keyv/test/test.js +0 -132
- package/node_modules/keyv/test/testdb.sqlite +0 -0
- package/releasetag.txt +0 -1
- package/version.txt +0 -1
- /package/node_modules/{get-stream → cacheable-request/node_modules/get-stream}/buffer-stream.js +0 -0
- /package/node_modules/{get-stream → cacheable-request/node_modules/get-stream}/index.d.ts +0 -0
- /package/node_modules/{get-stream → cacheable-request/node_modules/get-stream}/index.js +0 -0
- /package/node_modules/{decompress-response/node_modules/mimic-response → cacheable-request/node_modules/get-stream}/license +0 -0
- /package/node_modules/{get-stream → cacheable-request/node_modules/get-stream}/package.json +0 -0
- /package/node_modules/{get-stream → cacheable-request/node_modules/get-stream}/readme.md +0 -0
- /package/node_modules/{decompress-response/node_modules/mimic-response → mimic-response}/index.d.ts +0 -0
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A stream is an abstract interface for working with streaming data in Node.js.
|
|
3
|
-
* The `stream` module provides an API for implementing the stream interface.
|
|
3
|
+
* The `node:stream` module provides an API for implementing the stream interface.
|
|
4
4
|
*
|
|
5
5
|
* There are many stream objects provided by Node.js. For instance, a `request to an HTTP server` and `process.stdout` are both stream instances.
|
|
6
6
|
*
|
|
7
7
|
* Streams can be readable, writable, or both. All streams are instances of `EventEmitter`.
|
|
8
8
|
*
|
|
9
|
-
* To access the `stream` module:
|
|
9
|
+
* To access the `node:stream` module:
|
|
10
10
|
*
|
|
11
11
|
* ```js
|
|
12
|
-
* const stream = require('stream');
|
|
12
|
+
* const stream = require('node:stream');
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* The `stream` module is useful for creating new types of stream instances.
|
|
16
|
-
* usually not necessary to use the `stream` module to consume streams.
|
|
17
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
15
|
+
* The `node:stream` module is useful for creating new types of stream instances.
|
|
16
|
+
* It is usually not necessary to use the `node:stream` module to consume streams.
|
|
17
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/stream.js)
|
|
18
18
|
*/
|
|
19
19
|
declare module 'stream' {
|
|
20
20
|
import { EventEmitter, Abortable } from 'node:events';
|
|
21
|
+
import { Blob as NodeBlob } from 'node:buffer';
|
|
21
22
|
import * as streamPromises from 'node:stream/promises';
|
|
22
23
|
import * as streamConsumers from 'node:stream/consumers';
|
|
24
|
+
import * as streamWeb from 'node:stream/web';
|
|
23
25
|
class internal extends EventEmitter {
|
|
24
26
|
pipe<T extends NodeJS.WritableStream>(
|
|
25
27
|
destination: T,
|
|
@@ -28,6 +30,739 @@ declare module 'stream' {
|
|
|
28
30
|
}
|
|
29
31
|
): T;
|
|
30
32
|
}
|
|
33
|
+
import Stream = internal.Stream;
|
|
34
|
+
import Readable = internal.Readable;
|
|
35
|
+
import ReadableOptions = internal.ReadableOptions;
|
|
36
|
+
class ReadableBase extends Stream implements NodeJS.ReadableStream {
|
|
37
|
+
/**
|
|
38
|
+
* A utility method for creating Readable Streams out of iterators.
|
|
39
|
+
*/
|
|
40
|
+
static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
|
|
41
|
+
/**
|
|
42
|
+
* Returns whether the stream has been read from or cancelled.
|
|
43
|
+
* @since v16.8.0
|
|
44
|
+
*/
|
|
45
|
+
static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Returns whether the stream was destroyed or errored before emitting `'end'`.
|
|
48
|
+
* @since v16.8.0
|
|
49
|
+
* @experimental
|
|
50
|
+
*/
|
|
51
|
+
readonly readableAborted: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Is `true` if it is safe to call `readable.read()`, which means
|
|
54
|
+
* the stream has not been destroyed or emitted `'error'` or `'end'`.
|
|
55
|
+
* @since v11.4.0
|
|
56
|
+
*/
|
|
57
|
+
readable: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Returns whether `'data'` has been emitted.
|
|
60
|
+
* @since v16.7.0, v14.18.0
|
|
61
|
+
* @experimental
|
|
62
|
+
*/
|
|
63
|
+
readonly readableDidRead: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Getter for the property `encoding` of a given `Readable` stream. The `encoding`property can be set using the `readable.setEncoding()` method.
|
|
66
|
+
* @since v12.7.0
|
|
67
|
+
*/
|
|
68
|
+
readonly readableEncoding: BufferEncoding | null;
|
|
69
|
+
/**
|
|
70
|
+
* Becomes `true` when `'end'` event is emitted.
|
|
71
|
+
* @since v12.9.0
|
|
72
|
+
*/
|
|
73
|
+
readonly readableEnded: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* This property reflects the current state of a `Readable` stream as described
|
|
76
|
+
* in the `Three states` section.
|
|
77
|
+
* @since v9.4.0
|
|
78
|
+
*/
|
|
79
|
+
readonly readableFlowing: boolean | null;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the value of `highWaterMark` passed when creating this `Readable`.
|
|
82
|
+
* @since v9.3.0
|
|
83
|
+
*/
|
|
84
|
+
readonly readableHighWaterMark: number;
|
|
85
|
+
/**
|
|
86
|
+
* This property contains the number of bytes (or objects) in the queue
|
|
87
|
+
* ready to be read. The value provides introspection data regarding
|
|
88
|
+
* the status of the `highWaterMark`.
|
|
89
|
+
* @since v9.4.0
|
|
90
|
+
*/
|
|
91
|
+
readonly readableLength: number;
|
|
92
|
+
/**
|
|
93
|
+
* Getter for the property `objectMode` of a given `Readable` stream.
|
|
94
|
+
* @since v12.3.0
|
|
95
|
+
*/
|
|
96
|
+
readonly readableObjectMode: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Is `true` after `readable.destroy()` has been called.
|
|
99
|
+
* @since v8.0.0
|
|
100
|
+
*/
|
|
101
|
+
destroyed: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Is `true` after `'close'` has been emitted.
|
|
104
|
+
* @since v18.0.0
|
|
105
|
+
*/
|
|
106
|
+
readonly closed: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Returns error if the stream has been destroyed with an error.
|
|
109
|
+
* @since v18.0.0
|
|
110
|
+
*/
|
|
111
|
+
readonly errored: Error | null;
|
|
112
|
+
constructor(opts?: ReadableOptions);
|
|
113
|
+
_construct?(callback: (error?: Error | null) => void): void;
|
|
114
|
+
_read(size: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* The `readable.read()` method reads data out of the internal buffer and
|
|
117
|
+
* returns it. If no data is available to be read, `null` is returned. By default,
|
|
118
|
+
* the data is returned as a `Buffer` object unless an encoding has been
|
|
119
|
+
* specified using the `readable.setEncoding()` method or the stream is operating
|
|
120
|
+
* in object mode.
|
|
121
|
+
*
|
|
122
|
+
* The optional `size` argument specifies a specific number of bytes to read. If`size` bytes are not available to be read, `null` will be returned _unless_the stream has ended, in which
|
|
123
|
+
* case all of the data remaining in the internal
|
|
124
|
+
* buffer will be returned.
|
|
125
|
+
*
|
|
126
|
+
* If the `size` argument is not specified, all of the data contained in the
|
|
127
|
+
* internal buffer will be returned.
|
|
128
|
+
*
|
|
129
|
+
* The `size` argument must be less than or equal to 1 GiB.
|
|
130
|
+
*
|
|
131
|
+
* The `readable.read()` method should only be called on `Readable` streams
|
|
132
|
+
* operating in paused mode. In flowing mode, `readable.read()` is called
|
|
133
|
+
* automatically until the internal buffer is fully drained.
|
|
134
|
+
*
|
|
135
|
+
* ```js
|
|
136
|
+
* const readable = getReadableStreamSomehow();
|
|
137
|
+
*
|
|
138
|
+
* // 'readable' may be triggered multiple times as data is buffered in
|
|
139
|
+
* readable.on('readable', () => {
|
|
140
|
+
* let chunk;
|
|
141
|
+
* console.log('Stream is readable (new data received in buffer)');
|
|
142
|
+
* // Use a loop to make sure we read all currently available data
|
|
143
|
+
* while (null !== (chunk = readable.read())) {
|
|
144
|
+
* console.log(`Read ${chunk.length} bytes of data...`);
|
|
145
|
+
* }
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* // 'end' will be triggered once when there is no more data available
|
|
149
|
+
* readable.on('end', () => {
|
|
150
|
+
* console.log('Reached end of stream.');
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
|
|
155
|
+
* are not concatenated. A `while` loop is necessary to consume all data
|
|
156
|
+
* currently in the buffer. When reading a large file `.read()` may return `null`,
|
|
157
|
+
* having consumed all buffered content so far, but there is still more data to
|
|
158
|
+
* come not yet buffered. In this case a new `'readable'` event will be emitted
|
|
159
|
+
* when there is more data in the buffer. Finally the `'end'` event will be
|
|
160
|
+
* emitted when there is no more data to come.
|
|
161
|
+
*
|
|
162
|
+
* Therefore to read a file's whole contents from a `readable`, it is necessary
|
|
163
|
+
* to collect chunks across multiple `'readable'` events:
|
|
164
|
+
*
|
|
165
|
+
* ```js
|
|
166
|
+
* const chunks = [];
|
|
167
|
+
*
|
|
168
|
+
* readable.on('readable', () => {
|
|
169
|
+
* let chunk;
|
|
170
|
+
* while (null !== (chunk = readable.read())) {
|
|
171
|
+
* chunks.push(chunk);
|
|
172
|
+
* }
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* readable.on('end', () => {
|
|
176
|
+
* const content = chunks.join('');
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* A `Readable` stream in object mode will always return a single item from
|
|
181
|
+
* a call to `readable.read(size)`, regardless of the value of the`size` argument.
|
|
182
|
+
*
|
|
183
|
+
* If the `readable.read()` method returns a chunk of data, a `'data'` event will
|
|
184
|
+
* also be emitted.
|
|
185
|
+
*
|
|
186
|
+
* Calling {@link read} after the `'end'` event has
|
|
187
|
+
* been emitted will return `null`. No runtime error will be raised.
|
|
188
|
+
* @since v0.9.4
|
|
189
|
+
* @param size Optional argument to specify how much data to read.
|
|
190
|
+
*/
|
|
191
|
+
read(size?: number): any;
|
|
192
|
+
/**
|
|
193
|
+
* The `readable.setEncoding()` method sets the character encoding for
|
|
194
|
+
* data read from the `Readable` stream.
|
|
195
|
+
*
|
|
196
|
+
* By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
|
|
197
|
+
* to be returned as strings of the specified encoding rather than as `Buffer`objects. For instance, calling `readable.setEncoding('utf8')` will cause the
|
|
198
|
+
* output data to be interpreted as UTF-8 data, and passed as strings. Calling`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
|
|
199
|
+
* string format.
|
|
200
|
+
*
|
|
201
|
+
* The `Readable` stream will properly handle multi-byte characters delivered
|
|
202
|
+
* through the stream that would otherwise become improperly decoded if simply
|
|
203
|
+
* pulled from the stream as `Buffer` objects.
|
|
204
|
+
*
|
|
205
|
+
* ```js
|
|
206
|
+
* const readable = getReadableStreamSomehow();
|
|
207
|
+
* readable.setEncoding('utf8');
|
|
208
|
+
* readable.on('data', (chunk) => {
|
|
209
|
+
* assert.equal(typeof chunk, 'string');
|
|
210
|
+
* console.log('Got %d characters of string data:', chunk.length);
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
* @since v0.9.4
|
|
214
|
+
* @param encoding The encoding to use.
|
|
215
|
+
*/
|
|
216
|
+
setEncoding(encoding: BufferEncoding): this;
|
|
217
|
+
/**
|
|
218
|
+
* The `readable.pause()` method will cause a stream in flowing mode to stop
|
|
219
|
+
* emitting `'data'` events, switching out of flowing mode. Any data that
|
|
220
|
+
* becomes available will remain in the internal buffer.
|
|
221
|
+
*
|
|
222
|
+
* ```js
|
|
223
|
+
* const readable = getReadableStreamSomehow();
|
|
224
|
+
* readable.on('data', (chunk) => {
|
|
225
|
+
* console.log(`Received ${chunk.length} bytes of data.`);
|
|
226
|
+
* readable.pause();
|
|
227
|
+
* console.log('There will be no additional data for 1 second.');
|
|
228
|
+
* setTimeout(() => {
|
|
229
|
+
* console.log('Now data will start flowing again.');
|
|
230
|
+
* readable.resume();
|
|
231
|
+
* }, 1000);
|
|
232
|
+
* });
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* The `readable.pause()` method has no effect if there is a `'readable'`event listener.
|
|
236
|
+
* @since v0.9.4
|
|
237
|
+
*/
|
|
238
|
+
pause(): this;
|
|
239
|
+
/**
|
|
240
|
+
* The `readable.resume()` method causes an explicitly paused `Readable` stream to
|
|
241
|
+
* resume emitting `'data'` events, switching the stream into flowing mode.
|
|
242
|
+
*
|
|
243
|
+
* The `readable.resume()` method can be used to fully consume the data from a
|
|
244
|
+
* stream without actually processing any of that data:
|
|
245
|
+
*
|
|
246
|
+
* ```js
|
|
247
|
+
* getReadableStreamSomehow()
|
|
248
|
+
* .resume()
|
|
249
|
+
* .on('end', () => {
|
|
250
|
+
* console.log('Reached the end, but did not read anything.');
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* The `readable.resume()` method has no effect if there is a `'readable'`event listener.
|
|
255
|
+
* @since v0.9.4
|
|
256
|
+
*/
|
|
257
|
+
resume(): this;
|
|
258
|
+
/**
|
|
259
|
+
* The `readable.isPaused()` method returns the current operating state of the`Readable`. This is used primarily by the mechanism that underlies the`readable.pipe()` method. In most
|
|
260
|
+
* typical cases, there will be no reason to
|
|
261
|
+
* use this method directly.
|
|
262
|
+
*
|
|
263
|
+
* ```js
|
|
264
|
+
* const readable = new stream.Readable();
|
|
265
|
+
*
|
|
266
|
+
* readable.isPaused(); // === false
|
|
267
|
+
* readable.pause();
|
|
268
|
+
* readable.isPaused(); // === true
|
|
269
|
+
* readable.resume();
|
|
270
|
+
* readable.isPaused(); // === false
|
|
271
|
+
* ```
|
|
272
|
+
* @since v0.11.14
|
|
273
|
+
*/
|
|
274
|
+
isPaused(): boolean;
|
|
275
|
+
/**
|
|
276
|
+
* The `readable.unpipe()` method detaches a `Writable` stream previously attached
|
|
277
|
+
* using the {@link pipe} method.
|
|
278
|
+
*
|
|
279
|
+
* If the `destination` is not specified, then _all_ pipes are detached.
|
|
280
|
+
*
|
|
281
|
+
* If the `destination` is specified, but no pipe is set up for it, then
|
|
282
|
+
* the method does nothing.
|
|
283
|
+
*
|
|
284
|
+
* ```js
|
|
285
|
+
* const fs = require('node:fs');
|
|
286
|
+
* const readable = getReadableStreamSomehow();
|
|
287
|
+
* const writable = fs.createWriteStream('file.txt');
|
|
288
|
+
* // All the data from readable goes into 'file.txt',
|
|
289
|
+
* // but only for the first second.
|
|
290
|
+
* readable.pipe(writable);
|
|
291
|
+
* setTimeout(() => {
|
|
292
|
+
* console.log('Stop writing to file.txt.');
|
|
293
|
+
* readable.unpipe(writable);
|
|
294
|
+
* console.log('Manually close the file stream.');
|
|
295
|
+
* writable.end();
|
|
296
|
+
* }, 1000);
|
|
297
|
+
* ```
|
|
298
|
+
* @since v0.9.4
|
|
299
|
+
* @param destination Optional specific stream to unpipe
|
|
300
|
+
*/
|
|
301
|
+
unpipe(destination?: NodeJS.WritableStream): this;
|
|
302
|
+
/**
|
|
303
|
+
* Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
|
|
304
|
+
* same as `readable.push(null)`, after which no more data can be written. The EOF
|
|
305
|
+
* signal is put at the end of the buffer and any buffered data will still be
|
|
306
|
+
* flushed.
|
|
307
|
+
*
|
|
308
|
+
* The `readable.unshift()` method pushes a chunk of data back into the internal
|
|
309
|
+
* buffer. This is useful in certain situations where a stream is being consumed by
|
|
310
|
+
* code that needs to "un-consume" some amount of data that it has optimistically
|
|
311
|
+
* pulled out of the source, so that the data can be passed on to some other party.
|
|
312
|
+
*
|
|
313
|
+
* The `stream.unshift(chunk)` method cannot be called after the `'end'` event
|
|
314
|
+
* has been emitted or a runtime error will be thrown.
|
|
315
|
+
*
|
|
316
|
+
* Developers using `stream.unshift()` often should consider switching to
|
|
317
|
+
* use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
|
|
318
|
+
*
|
|
319
|
+
* ```js
|
|
320
|
+
* // Pull off a header delimited by \n\n.
|
|
321
|
+
* // Use unshift() if we get too much.
|
|
322
|
+
* // Call the callback with (error, header, stream).
|
|
323
|
+
* const { StringDecoder } = require('node:string_decoder');
|
|
324
|
+
* function parseHeader(stream, callback) {
|
|
325
|
+
* stream.on('error', callback);
|
|
326
|
+
* stream.on('readable', onReadable);
|
|
327
|
+
* const decoder = new StringDecoder('utf8');
|
|
328
|
+
* let header = '';
|
|
329
|
+
* function onReadable() {
|
|
330
|
+
* let chunk;
|
|
331
|
+
* while (null !== (chunk = stream.read())) {
|
|
332
|
+
* const str = decoder.write(chunk);
|
|
333
|
+
* if (str.includes('\n\n')) {
|
|
334
|
+
* // Found the header boundary.
|
|
335
|
+
* const split = str.split(/\n\n/);
|
|
336
|
+
* header += split.shift();
|
|
337
|
+
* const remaining = split.join('\n\n');
|
|
338
|
+
* const buf = Buffer.from(remaining, 'utf8');
|
|
339
|
+
* stream.removeListener('error', callback);
|
|
340
|
+
* // Remove the 'readable' listener before unshifting.
|
|
341
|
+
* stream.removeListener('readable', onReadable);
|
|
342
|
+
* if (buf.length)
|
|
343
|
+
* stream.unshift(buf);
|
|
344
|
+
* // Now the body of the message can be read from the stream.
|
|
345
|
+
* callback(null, header, stream);
|
|
346
|
+
* return;
|
|
347
|
+
* }
|
|
348
|
+
* // Still reading the header.
|
|
349
|
+
* header += str;
|
|
350
|
+
* }
|
|
351
|
+
* }
|
|
352
|
+
* }
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* Unlike {@link push}, `stream.unshift(chunk)` will not
|
|
356
|
+
* end the reading process by resetting the internal reading state of the stream.
|
|
357
|
+
* This can cause unexpected results if `readable.unshift()` is called during a
|
|
358
|
+
* read (i.e. from within a {@link _read} implementation on a
|
|
359
|
+
* custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
|
|
360
|
+
* however it is best to simply avoid calling `readable.unshift()` while in the
|
|
361
|
+
* process of performing a read.
|
|
362
|
+
* @since v0.9.11
|
|
363
|
+
* @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer`, `Uint8Array`, or `null`. For object mode
|
|
364
|
+
* streams, `chunk` may be any JavaScript value.
|
|
365
|
+
* @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
|
|
366
|
+
*/
|
|
367
|
+
unshift(chunk: any, encoding?: BufferEncoding): void;
|
|
368
|
+
/**
|
|
369
|
+
* Prior to Node.js 0.10, streams did not implement the entire `node:stream`module API as it is currently defined. (See `Compatibility` for more
|
|
370
|
+
* information.)
|
|
371
|
+
*
|
|
372
|
+
* When using an older Node.js library that emits `'data'` events and has a {@link pause} method that is advisory only, the`readable.wrap()` method can be used to create a `Readable`
|
|
373
|
+
* stream that uses
|
|
374
|
+
* the old stream as its data source.
|
|
375
|
+
*
|
|
376
|
+
* It will rarely be necessary to use `readable.wrap()` but the method has been
|
|
377
|
+
* provided as a convenience for interacting with older Node.js applications and
|
|
378
|
+
* libraries.
|
|
379
|
+
*
|
|
380
|
+
* ```js
|
|
381
|
+
* const { OldReader } = require('./old-api-module.js');
|
|
382
|
+
* const { Readable } = require('node:stream');
|
|
383
|
+
* const oreader = new OldReader();
|
|
384
|
+
* const myReader = new Readable().wrap(oreader);
|
|
385
|
+
*
|
|
386
|
+
* myReader.on('readable', () => {
|
|
387
|
+
* myReader.read(); // etc.
|
|
388
|
+
* });
|
|
389
|
+
* ```
|
|
390
|
+
* @since v0.9.4
|
|
391
|
+
* @param stream An "old style" readable stream
|
|
392
|
+
*/
|
|
393
|
+
wrap(stream: NodeJS.ReadableStream): this;
|
|
394
|
+
push(chunk: any, encoding?: BufferEncoding): boolean;
|
|
395
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
396
|
+
/**
|
|
397
|
+
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
|
|
398
|
+
* stream will release any internal resources and subsequent calls to `push()`will be ignored.
|
|
399
|
+
*
|
|
400
|
+
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
401
|
+
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
402
|
+
*
|
|
403
|
+
* Implementors should not override this method, but instead implement `readable._destroy()`.
|
|
404
|
+
* @since v8.0.0
|
|
405
|
+
* @param error Error which will be passed as payload in `'error'` event
|
|
406
|
+
*/
|
|
407
|
+
destroy(error?: Error): this;
|
|
408
|
+
/**
|
|
409
|
+
* Event emitter
|
|
410
|
+
* The defined events on documents including:
|
|
411
|
+
* 1. close
|
|
412
|
+
* 2. data
|
|
413
|
+
* 3. end
|
|
414
|
+
* 4. error
|
|
415
|
+
* 5. pause
|
|
416
|
+
* 6. readable
|
|
417
|
+
* 7. resume
|
|
418
|
+
*/
|
|
419
|
+
addListener(event: 'close', listener: () => void): this;
|
|
420
|
+
addListener(event: 'data', listener: (chunk: any) => void): this;
|
|
421
|
+
addListener(event: 'end', listener: () => void): this;
|
|
422
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
423
|
+
addListener(event: 'pause', listener: () => void): this;
|
|
424
|
+
addListener(event: 'readable', listener: () => void): this;
|
|
425
|
+
addListener(event: 'resume', listener: () => void): this;
|
|
426
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
427
|
+
emit(event: 'close'): boolean;
|
|
428
|
+
emit(event: 'data', chunk: any): boolean;
|
|
429
|
+
emit(event: 'end'): boolean;
|
|
430
|
+
emit(event: 'error', err: Error): boolean;
|
|
431
|
+
emit(event: 'pause'): boolean;
|
|
432
|
+
emit(event: 'readable'): boolean;
|
|
433
|
+
emit(event: 'resume'): boolean;
|
|
434
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
435
|
+
on(event: 'close', listener: () => void): this;
|
|
436
|
+
on(event: 'data', listener: (chunk: any) => void): this;
|
|
437
|
+
on(event: 'end', listener: () => void): this;
|
|
438
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
439
|
+
on(event: 'pause', listener: () => void): this;
|
|
440
|
+
on(event: 'readable', listener: () => void): this;
|
|
441
|
+
on(event: 'resume', listener: () => void): this;
|
|
442
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
443
|
+
once(event: 'close', listener: () => void): this;
|
|
444
|
+
once(event: 'data', listener: (chunk: any) => void): this;
|
|
445
|
+
once(event: 'end', listener: () => void): this;
|
|
446
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
447
|
+
once(event: 'pause', listener: () => void): this;
|
|
448
|
+
once(event: 'readable', listener: () => void): this;
|
|
449
|
+
once(event: 'resume', listener: () => void): this;
|
|
450
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
451
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
452
|
+
prependListener(event: 'data', listener: (chunk: any) => void): this;
|
|
453
|
+
prependListener(event: 'end', listener: () => void): this;
|
|
454
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
455
|
+
prependListener(event: 'pause', listener: () => void): this;
|
|
456
|
+
prependListener(event: 'readable', listener: () => void): this;
|
|
457
|
+
prependListener(event: 'resume', listener: () => void): this;
|
|
458
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
459
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
460
|
+
prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
|
|
461
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
|
462
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
463
|
+
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
464
|
+
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
465
|
+
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
466
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
467
|
+
removeListener(event: 'close', listener: () => void): this;
|
|
468
|
+
removeListener(event: 'data', listener: (chunk: any) => void): this;
|
|
469
|
+
removeListener(event: 'end', listener: () => void): this;
|
|
470
|
+
removeListener(event: 'error', listener: (err: Error) => void): this;
|
|
471
|
+
removeListener(event: 'pause', listener: () => void): this;
|
|
472
|
+
removeListener(event: 'readable', listener: () => void): this;
|
|
473
|
+
removeListener(event: 'resume', listener: () => void): this;
|
|
474
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
475
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
|
476
|
+
}
|
|
477
|
+
import WritableOptions = internal.WritableOptions;
|
|
478
|
+
class WritableBase extends Stream implements NodeJS.WritableStream {
|
|
479
|
+
/**
|
|
480
|
+
* Is `true` if it is safe to call `writable.write()`, which means
|
|
481
|
+
* the stream has not been destroyed, errored, or ended.
|
|
482
|
+
* @since v11.4.0
|
|
483
|
+
*/
|
|
484
|
+
readonly writable: boolean;
|
|
485
|
+
/**
|
|
486
|
+
* Is `true` after `writable.end()` has been called. This property
|
|
487
|
+
* does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
|
|
488
|
+
* @since v12.9.0
|
|
489
|
+
*/
|
|
490
|
+
readonly writableEnded: boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Is set to `true` immediately before the `'finish'` event is emitted.
|
|
493
|
+
* @since v12.6.0
|
|
494
|
+
*/
|
|
495
|
+
readonly writableFinished: boolean;
|
|
496
|
+
/**
|
|
497
|
+
* Return the value of `highWaterMark` passed when creating this `Writable`.
|
|
498
|
+
* @since v9.3.0
|
|
499
|
+
*/
|
|
500
|
+
readonly writableHighWaterMark: number;
|
|
501
|
+
/**
|
|
502
|
+
* This property contains the number of bytes (or objects) in the queue
|
|
503
|
+
* ready to be written. The value provides introspection data regarding
|
|
504
|
+
* the status of the `highWaterMark`.
|
|
505
|
+
* @since v9.4.0
|
|
506
|
+
*/
|
|
507
|
+
readonly writableLength: number;
|
|
508
|
+
/**
|
|
509
|
+
* Getter for the property `objectMode` of a given `Writable` stream.
|
|
510
|
+
* @since v12.3.0
|
|
511
|
+
*/
|
|
512
|
+
readonly writableObjectMode: boolean;
|
|
513
|
+
/**
|
|
514
|
+
* Number of times `writable.uncork()` needs to be
|
|
515
|
+
* called in order to fully uncork the stream.
|
|
516
|
+
* @since v13.2.0, v12.16.0
|
|
517
|
+
*/
|
|
518
|
+
readonly writableCorked: number;
|
|
519
|
+
/**
|
|
520
|
+
* Is `true` after `writable.destroy()` has been called.
|
|
521
|
+
* @since v8.0.0
|
|
522
|
+
*/
|
|
523
|
+
destroyed: boolean;
|
|
524
|
+
/**
|
|
525
|
+
* Is `true` after `'close'` has been emitted.
|
|
526
|
+
* @since v18.0.0
|
|
527
|
+
*/
|
|
528
|
+
readonly closed: boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Returns error if the stream has been destroyed with an error.
|
|
531
|
+
* @since v18.0.0
|
|
532
|
+
*/
|
|
533
|
+
readonly errored: Error | null;
|
|
534
|
+
/**
|
|
535
|
+
* Is `true` if the stream's buffer has been full and stream will emit `'drain'`.
|
|
536
|
+
* @since v15.2.0, v14.17.0
|
|
537
|
+
*/
|
|
538
|
+
readonly writableNeedDrain: boolean;
|
|
539
|
+
constructor(opts?: WritableOptions);
|
|
540
|
+
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
541
|
+
_writev?(
|
|
542
|
+
chunks: Array<{
|
|
543
|
+
chunk: any;
|
|
544
|
+
encoding: BufferEncoding;
|
|
545
|
+
}>,
|
|
546
|
+
callback: (error?: Error | null) => void
|
|
547
|
+
): void;
|
|
548
|
+
_construct?(callback: (error?: Error | null) => void): void;
|
|
549
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
550
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
551
|
+
/**
|
|
552
|
+
* The `writable.write()` method writes some data to the stream, and calls the
|
|
553
|
+
* supplied `callback` once the data has been fully handled. If an error
|
|
554
|
+
* occurs, the `callback` will be called with the error as its
|
|
555
|
+
* first argument. The `callback` is called asynchronously and before `'error'` is
|
|
556
|
+
* emitted.
|
|
557
|
+
*
|
|
558
|
+
* The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
|
|
559
|
+
* If `false` is returned, further attempts to write data to the stream should
|
|
560
|
+
* stop until the `'drain'` event is emitted.
|
|
561
|
+
*
|
|
562
|
+
* While a stream is not draining, calls to `write()` will buffer `chunk`, and
|
|
563
|
+
* return false. Once all currently buffered chunks are drained (accepted for
|
|
564
|
+
* delivery by the operating system), the `'drain'` event will be emitted.
|
|
565
|
+
* Once `write()` returns false, do not write more chunks
|
|
566
|
+
* until the `'drain'` event is emitted. While calling `write()` on a stream that
|
|
567
|
+
* is not draining is allowed, Node.js will buffer all written chunks until
|
|
568
|
+
* maximum memory usage occurs, at which point it will abort unconditionally.
|
|
569
|
+
* Even before it aborts, high memory usage will cause poor garbage collector
|
|
570
|
+
* performance and high RSS (which is not typically released back to the system,
|
|
571
|
+
* even after the memory is no longer required). Since TCP sockets may never
|
|
572
|
+
* drain if the remote peer does not read the data, writing a socket that is
|
|
573
|
+
* not draining may lead to a remotely exploitable vulnerability.
|
|
574
|
+
*
|
|
575
|
+
* Writing data while the stream is not draining is particularly
|
|
576
|
+
* problematic for a `Transform`, because the `Transform` streams are paused
|
|
577
|
+
* by default until they are piped or a `'data'` or `'readable'` event handler
|
|
578
|
+
* is added.
|
|
579
|
+
*
|
|
580
|
+
* If the data to be written can be generated or fetched on demand, it is
|
|
581
|
+
* recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
|
|
582
|
+
* possible to respect backpressure and avoid memory issues using the `'drain'` event:
|
|
583
|
+
*
|
|
584
|
+
* ```js
|
|
585
|
+
* function write(data, cb) {
|
|
586
|
+
* if (!stream.write(data)) {
|
|
587
|
+
* stream.once('drain', cb);
|
|
588
|
+
* } else {
|
|
589
|
+
* process.nextTick(cb);
|
|
590
|
+
* }
|
|
591
|
+
* }
|
|
592
|
+
*
|
|
593
|
+
* // Wait for cb to be called before doing any other write.
|
|
594
|
+
* write('hello', () => {
|
|
595
|
+
* console.log('Write completed, do more writes now.');
|
|
596
|
+
* });
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* A `Writable` stream in object mode will always ignore the `encoding` argument.
|
|
600
|
+
* @since v0.9.4
|
|
601
|
+
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
|
|
602
|
+
* JavaScript value other than `null`.
|
|
603
|
+
* @param [encoding='utf8'] The encoding, if `chunk` is a string.
|
|
604
|
+
* @param callback Callback for when this chunk of data is flushed.
|
|
605
|
+
* @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
|
|
606
|
+
*/
|
|
607
|
+
write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
|
|
608
|
+
write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
|
|
609
|
+
/**
|
|
610
|
+
* The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
|
|
611
|
+
* @since v0.11.15
|
|
612
|
+
* @param encoding The new default encoding
|
|
613
|
+
*/
|
|
614
|
+
setDefaultEncoding(encoding: BufferEncoding): this;
|
|
615
|
+
/**
|
|
616
|
+
* Calling the `writable.end()` method signals that no more data will be written
|
|
617
|
+
* to the `Writable`. The optional `chunk` and `encoding` arguments allow one
|
|
618
|
+
* final additional chunk of data to be written immediately before closing the
|
|
619
|
+
* stream.
|
|
620
|
+
*
|
|
621
|
+
* Calling the {@link write} method after calling {@link end} will raise an error.
|
|
622
|
+
*
|
|
623
|
+
* ```js
|
|
624
|
+
* // Write 'hello, ' and then end with 'world!'.
|
|
625
|
+
* const fs = require('node:fs');
|
|
626
|
+
* const file = fs.createWriteStream('example.txt');
|
|
627
|
+
* file.write('hello, ');
|
|
628
|
+
* file.end('world!');
|
|
629
|
+
* // Writing more now is not allowed!
|
|
630
|
+
* ```
|
|
631
|
+
* @since v0.9.4
|
|
632
|
+
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
|
|
633
|
+
* JavaScript value other than `null`.
|
|
634
|
+
* @param encoding The encoding if `chunk` is a string
|
|
635
|
+
* @param callback Callback for when the stream is finished.
|
|
636
|
+
*/
|
|
637
|
+
end(cb?: () => void): this;
|
|
638
|
+
end(chunk: any, cb?: () => void): this;
|
|
639
|
+
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
640
|
+
/**
|
|
641
|
+
* The `writable.cork()` method forces all written data to be buffered in memory.
|
|
642
|
+
* The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
|
|
643
|
+
*
|
|
644
|
+
* The primary intent of `writable.cork()` is to accommodate a situation in which
|
|
645
|
+
* several small chunks are written to the stream in rapid succession. Instead of
|
|
646
|
+
* immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
|
|
647
|
+
* all to `writable._writev()`, if present. This prevents a head-of-line blocking
|
|
648
|
+
* situation where data is being buffered while waiting for the first small chunk
|
|
649
|
+
* to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
|
|
650
|
+
*
|
|
651
|
+
* See also: `writable.uncork()`, `writable._writev()`.
|
|
652
|
+
* @since v0.11.2
|
|
653
|
+
*/
|
|
654
|
+
cork(): void;
|
|
655
|
+
/**
|
|
656
|
+
* The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
|
|
657
|
+
*
|
|
658
|
+
* When using `writable.cork()` and `writable.uncork()` to manage the buffering
|
|
659
|
+
* of writes to a stream, defer calls to `writable.uncork()` using`process.nextTick()`. Doing so allows batching of all`writable.write()` calls that occur within a given Node.js event
|
|
660
|
+
* loop phase.
|
|
661
|
+
*
|
|
662
|
+
* ```js
|
|
663
|
+
* stream.cork();
|
|
664
|
+
* stream.write('some ');
|
|
665
|
+
* stream.write('data ');
|
|
666
|
+
* process.nextTick(() => stream.uncork());
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* If the `writable.cork()` method is called multiple times on a stream, the
|
|
670
|
+
* same number of calls to `writable.uncork()` must be called to flush the buffered
|
|
671
|
+
* data.
|
|
672
|
+
*
|
|
673
|
+
* ```js
|
|
674
|
+
* stream.cork();
|
|
675
|
+
* stream.write('some ');
|
|
676
|
+
* stream.cork();
|
|
677
|
+
* stream.write('data ');
|
|
678
|
+
* process.nextTick(() => {
|
|
679
|
+
* stream.uncork();
|
|
680
|
+
* // The data will not be flushed until uncork() is called a second time.
|
|
681
|
+
* stream.uncork();
|
|
682
|
+
* });
|
|
683
|
+
* ```
|
|
684
|
+
*
|
|
685
|
+
* See also: `writable.cork()`.
|
|
686
|
+
* @since v0.11.2
|
|
687
|
+
*/
|
|
688
|
+
uncork(): void;
|
|
689
|
+
/**
|
|
690
|
+
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the writable
|
|
691
|
+
* stream has ended and subsequent calls to `write()` or `end()` will result in
|
|
692
|
+
* an `ERR_STREAM_DESTROYED` error.
|
|
693
|
+
* This is a destructive and immediate way to destroy a stream. Previous calls to`write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
|
|
694
|
+
* Use `end()` instead of destroy if data should flush before close, or wait for
|
|
695
|
+
* the `'drain'` event before destroying the stream.
|
|
696
|
+
*
|
|
697
|
+
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
698
|
+
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
699
|
+
*
|
|
700
|
+
* Implementors should not override this method,
|
|
701
|
+
* but instead implement `writable._destroy()`.
|
|
702
|
+
* @since v8.0.0
|
|
703
|
+
* @param error Optional, an error to emit with `'error'` event.
|
|
704
|
+
*/
|
|
705
|
+
destroy(error?: Error): this;
|
|
706
|
+
/**
|
|
707
|
+
* Event emitter
|
|
708
|
+
* The defined events on documents including:
|
|
709
|
+
* 1. close
|
|
710
|
+
* 2. drain
|
|
711
|
+
* 3. error
|
|
712
|
+
* 4. finish
|
|
713
|
+
* 5. pipe
|
|
714
|
+
* 6. unpipe
|
|
715
|
+
*/
|
|
716
|
+
addListener(event: 'close', listener: () => void): this;
|
|
717
|
+
addListener(event: 'drain', listener: () => void): this;
|
|
718
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
719
|
+
addListener(event: 'finish', listener: () => void): this;
|
|
720
|
+
addListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
721
|
+
addListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
722
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
723
|
+
emit(event: 'close'): boolean;
|
|
724
|
+
emit(event: 'drain'): boolean;
|
|
725
|
+
emit(event: 'error', err: Error): boolean;
|
|
726
|
+
emit(event: 'finish'): boolean;
|
|
727
|
+
emit(event: 'pipe', src: Readable): boolean;
|
|
728
|
+
emit(event: 'unpipe', src: Readable): boolean;
|
|
729
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
730
|
+
on(event: 'close', listener: () => void): this;
|
|
731
|
+
on(event: 'drain', listener: () => void): this;
|
|
732
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
733
|
+
on(event: 'finish', listener: () => void): this;
|
|
734
|
+
on(event: 'pipe', listener: (src: Readable) => void): this;
|
|
735
|
+
on(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
736
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
737
|
+
once(event: 'close', listener: () => void): this;
|
|
738
|
+
once(event: 'drain', listener: () => void): this;
|
|
739
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
740
|
+
once(event: 'finish', listener: () => void): this;
|
|
741
|
+
once(event: 'pipe', listener: (src: Readable) => void): this;
|
|
742
|
+
once(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
743
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
744
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
745
|
+
prependListener(event: 'drain', listener: () => void): this;
|
|
746
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
747
|
+
prependListener(event: 'finish', listener: () => void): this;
|
|
748
|
+
prependListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
749
|
+
prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
750
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
751
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
752
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
753
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
754
|
+
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
755
|
+
prependOnceListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
756
|
+
prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
757
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
758
|
+
removeListener(event: 'close', listener: () => void): this;
|
|
759
|
+
removeListener(event: 'drain', listener: () => void): this;
|
|
760
|
+
removeListener(event: 'error', listener: (err: Error) => void): this;
|
|
761
|
+
removeListener(event: 'finish', listener: () => void): this;
|
|
762
|
+
removeListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
763
|
+
removeListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
764
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
765
|
+
}
|
|
31
766
|
namespace internal {
|
|
32
767
|
class Stream extends internal {
|
|
33
768
|
constructor(opts?: ReadableOptions);
|
|
@@ -47,726 +782,50 @@ declare module 'stream' {
|
|
|
47
782
|
/**
|
|
48
783
|
* @since v0.9.4
|
|
49
784
|
*/
|
|
50
|
-
class Readable extends
|
|
51
|
-
/**
|
|
52
|
-
* A utility method for creating Readable Streams out of iterators.
|
|
53
|
-
*/
|
|
54
|
-
static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
|
|
55
|
-
/**
|
|
56
|
-
* Returns whether the stream has been read from or cancelled.
|
|
57
|
-
* @since v16.8.0
|
|
58
|
-
*/
|
|
59
|
-
static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
|
|
785
|
+
class Readable extends ReadableBase {
|
|
60
786
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @since
|
|
787
|
+
* A utility method for creating a `Readable` from a web `ReadableStream`.
|
|
788
|
+
* @since v17.0.0
|
|
63
789
|
* @experimental
|
|
64
790
|
*/
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Is `true` if it is safe to call `readable.read()`, which means
|
|
68
|
-
* the stream has not been destroyed or emitted `'error'` or `'end'`.
|
|
69
|
-
* @since v11.4.0
|
|
70
|
-
*/
|
|
71
|
-
readable: boolean;
|
|
791
|
+
static fromWeb(readableStream: streamWeb.ReadableStream, options?: Pick<ReadableOptions, 'encoding' | 'highWaterMark' | 'objectMode' | 'signal'>): Readable;
|
|
72
792
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @since
|
|
793
|
+
* A utility method for creating a web `ReadableStream` from a `Readable`.
|
|
794
|
+
* @since v17.0.0
|
|
75
795
|
* @experimental
|
|
76
796
|
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Getter for the property `encoding` of a given `Readable` stream. The `encoding`property can be set using the `readable.setEncoding()` method.
|
|
80
|
-
* @since v12.7.0
|
|
81
|
-
*/
|
|
82
|
-
readonly readableEncoding: BufferEncoding | null;
|
|
83
|
-
/**
|
|
84
|
-
* Becomes `true` when `'end'` event is emitted.
|
|
85
|
-
* @since v12.9.0
|
|
86
|
-
*/
|
|
87
|
-
readonly readableEnded: boolean;
|
|
88
|
-
/**
|
|
89
|
-
* This property reflects the current state of a `Readable` stream as described
|
|
90
|
-
* in the `Three states` section.
|
|
91
|
-
* @since v9.4.0
|
|
92
|
-
*/
|
|
93
|
-
readonly readableFlowing: boolean | null;
|
|
94
|
-
/**
|
|
95
|
-
* Returns the value of `highWaterMark` passed when creating this `Readable`.
|
|
96
|
-
* @since v9.3.0
|
|
97
|
-
*/
|
|
98
|
-
readonly readableHighWaterMark: number;
|
|
99
|
-
/**
|
|
100
|
-
* This property contains the number of bytes (or objects) in the queue
|
|
101
|
-
* ready to be read. The value provides introspection data regarding
|
|
102
|
-
* the status of the `highWaterMark`.
|
|
103
|
-
* @since v9.4.0
|
|
104
|
-
*/
|
|
105
|
-
readonly readableLength: number;
|
|
106
|
-
/**
|
|
107
|
-
* Getter for the property `objectMode` of a given `Readable` stream.
|
|
108
|
-
* @since v12.3.0
|
|
109
|
-
*/
|
|
110
|
-
readonly readableObjectMode: boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Is `true` after `readable.destroy()` has been called.
|
|
113
|
-
* @since v8.0.0
|
|
114
|
-
*/
|
|
115
|
-
destroyed: boolean;
|
|
116
|
-
constructor(opts?: ReadableOptions);
|
|
117
|
-
_construct?(callback: (error?: Error | null) => void): void;
|
|
118
|
-
_read(size: number): void;
|
|
119
|
-
/**
|
|
120
|
-
* The `readable.read()` method pulls some data out of the internal buffer and
|
|
121
|
-
* returns it. If no data available to be read, `null` is returned. By default,
|
|
122
|
-
* the data will be returned as a `Buffer` object unless an encoding has been
|
|
123
|
-
* specified using the `readable.setEncoding()` method or the stream is operating
|
|
124
|
-
* in object mode.
|
|
125
|
-
*
|
|
126
|
-
* The optional `size` argument specifies a specific number of bytes to read. If`size` bytes are not available to be read, `null` will be returned _unless_the stream has ended, in which
|
|
127
|
-
* case all of the data remaining in the internal
|
|
128
|
-
* buffer will be returned.
|
|
129
|
-
*
|
|
130
|
-
* If the `size` argument is not specified, all of the data contained in the
|
|
131
|
-
* internal buffer will be returned.
|
|
132
|
-
*
|
|
133
|
-
* The `size` argument must be less than or equal to 1 GiB.
|
|
134
|
-
*
|
|
135
|
-
* The `readable.read()` method should only be called on `Readable` streams
|
|
136
|
-
* operating in paused mode. In flowing mode, `readable.read()` is called
|
|
137
|
-
* automatically until the internal buffer is fully drained.
|
|
138
|
-
*
|
|
139
|
-
* ```js
|
|
140
|
-
* const readable = getReadableStreamSomehow();
|
|
141
|
-
*
|
|
142
|
-
* // 'readable' may be triggered multiple times as data is buffered in
|
|
143
|
-
* readable.on('readable', () => {
|
|
144
|
-
* let chunk;
|
|
145
|
-
* console.log('Stream is readable (new data received in buffer)');
|
|
146
|
-
* // Use a loop to make sure we read all currently available data
|
|
147
|
-
* while (null !== (chunk = readable.read())) {
|
|
148
|
-
* console.log(`Read ${chunk.length} bytes of data...`);
|
|
149
|
-
* }
|
|
150
|
-
* });
|
|
151
|
-
*
|
|
152
|
-
* // 'end' will be triggered once when there is no more data available
|
|
153
|
-
* readable.on('end', () => {
|
|
154
|
-
* console.log('Reached end of stream.');
|
|
155
|
-
* });
|
|
156
|
-
* ```
|
|
157
|
-
*
|
|
158
|
-
* Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
|
|
159
|
-
* are not concatenated. A `while` loop is necessary to consume all data
|
|
160
|
-
* currently in the buffer. When reading a large file `.read()` may return `null`,
|
|
161
|
-
* having consumed all buffered content so far, but there is still more data to
|
|
162
|
-
* come not yet buffered. In this case a new `'readable'` event will be emitted
|
|
163
|
-
* when there is more data in the buffer. Finally the `'end'` event will be
|
|
164
|
-
* emitted when there is no more data to come.
|
|
165
|
-
*
|
|
166
|
-
* Therefore to read a file's whole contents from a `readable`, it is necessary
|
|
167
|
-
* to collect chunks across multiple `'readable'` events:
|
|
168
|
-
*
|
|
169
|
-
* ```js
|
|
170
|
-
* const chunks = [];
|
|
171
|
-
*
|
|
172
|
-
* readable.on('readable', () => {
|
|
173
|
-
* let chunk;
|
|
174
|
-
* while (null !== (chunk = readable.read())) {
|
|
175
|
-
* chunks.push(chunk);
|
|
176
|
-
* }
|
|
177
|
-
* });
|
|
178
|
-
*
|
|
179
|
-
* readable.on('end', () => {
|
|
180
|
-
* const content = chunks.join('');
|
|
181
|
-
* });
|
|
182
|
-
* ```
|
|
183
|
-
*
|
|
184
|
-
* A `Readable` stream in object mode will always return a single item from
|
|
185
|
-
* a call to `readable.read(size)`, regardless of the value of the`size` argument.
|
|
186
|
-
*
|
|
187
|
-
* If the `readable.read()` method returns a chunk of data, a `'data'` event will
|
|
188
|
-
* also be emitted.
|
|
189
|
-
*
|
|
190
|
-
* Calling {@link read} after the `'end'` event has
|
|
191
|
-
* been emitted will return `null`. No runtime error will be raised.
|
|
192
|
-
* @since v0.9.4
|
|
193
|
-
* @param size Optional argument to specify how much data to read.
|
|
194
|
-
*/
|
|
195
|
-
read(size?: number): any;
|
|
196
|
-
/**
|
|
197
|
-
* The `readable.setEncoding()` method sets the character encoding for
|
|
198
|
-
* data read from the `Readable` stream.
|
|
199
|
-
*
|
|
200
|
-
* By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
|
|
201
|
-
* to be returned as strings of the specified encoding rather than as `Buffer`objects. For instance, calling `readable.setEncoding('utf8')` will cause the
|
|
202
|
-
* output data to be interpreted as UTF-8 data, and passed as strings. Calling`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
|
|
203
|
-
* string format.
|
|
204
|
-
*
|
|
205
|
-
* The `Readable` stream will properly handle multi-byte characters delivered
|
|
206
|
-
* through the stream that would otherwise become improperly decoded if simply
|
|
207
|
-
* pulled from the stream as `Buffer` objects.
|
|
208
|
-
*
|
|
209
|
-
* ```js
|
|
210
|
-
* const readable = getReadableStreamSomehow();
|
|
211
|
-
* readable.setEncoding('utf8');
|
|
212
|
-
* readable.on('data', (chunk) => {
|
|
213
|
-
* assert.equal(typeof chunk, 'string');
|
|
214
|
-
* console.log('Got %d characters of string data:', chunk.length);
|
|
215
|
-
* });
|
|
216
|
-
* ```
|
|
217
|
-
* @since v0.9.4
|
|
218
|
-
* @param encoding The encoding to use.
|
|
219
|
-
*/
|
|
220
|
-
setEncoding(encoding: BufferEncoding): this;
|
|
221
|
-
/**
|
|
222
|
-
* The `readable.pause()` method will cause a stream in flowing mode to stop
|
|
223
|
-
* emitting `'data'` events, switching out of flowing mode. Any data that
|
|
224
|
-
* becomes available will remain in the internal buffer.
|
|
225
|
-
*
|
|
226
|
-
* ```js
|
|
227
|
-
* const readable = getReadableStreamSomehow();
|
|
228
|
-
* readable.on('data', (chunk) => {
|
|
229
|
-
* console.log(`Received ${chunk.length} bytes of data.`);
|
|
230
|
-
* readable.pause();
|
|
231
|
-
* console.log('There will be no additional data for 1 second.');
|
|
232
|
-
* setTimeout(() => {
|
|
233
|
-
* console.log('Now data will start flowing again.');
|
|
234
|
-
* readable.resume();
|
|
235
|
-
* }, 1000);
|
|
236
|
-
* });
|
|
237
|
-
* ```
|
|
238
|
-
*
|
|
239
|
-
* The `readable.pause()` method has no effect if there is a `'readable'`event listener.
|
|
240
|
-
* @since v0.9.4
|
|
241
|
-
*/
|
|
242
|
-
pause(): this;
|
|
243
|
-
/**
|
|
244
|
-
* The `readable.resume()` method causes an explicitly paused `Readable` stream to
|
|
245
|
-
* resume emitting `'data'` events, switching the stream into flowing mode.
|
|
246
|
-
*
|
|
247
|
-
* The `readable.resume()` method can be used to fully consume the data from a
|
|
248
|
-
* stream without actually processing any of that data:
|
|
249
|
-
*
|
|
250
|
-
* ```js
|
|
251
|
-
* getReadableStreamSomehow()
|
|
252
|
-
* .resume()
|
|
253
|
-
* .on('end', () => {
|
|
254
|
-
* console.log('Reached the end, but did not read anything.');
|
|
255
|
-
* });
|
|
256
|
-
* ```
|
|
257
|
-
*
|
|
258
|
-
* The `readable.resume()` method has no effect if there is a `'readable'`event listener.
|
|
259
|
-
* @since v0.9.4
|
|
260
|
-
*/
|
|
261
|
-
resume(): this;
|
|
262
|
-
/**
|
|
263
|
-
* The `readable.isPaused()` method returns the current operating state of the`Readable`. This is used primarily by the mechanism that underlies the`readable.pipe()` method. In most
|
|
264
|
-
* typical cases, there will be no reason to
|
|
265
|
-
* use this method directly.
|
|
266
|
-
*
|
|
267
|
-
* ```js
|
|
268
|
-
* const readable = new stream.Readable();
|
|
269
|
-
*
|
|
270
|
-
* readable.isPaused(); // === false
|
|
271
|
-
* readable.pause();
|
|
272
|
-
* readable.isPaused(); // === true
|
|
273
|
-
* readable.resume();
|
|
274
|
-
* readable.isPaused(); // === false
|
|
275
|
-
* ```
|
|
276
|
-
* @since v0.11.14
|
|
277
|
-
*/
|
|
278
|
-
isPaused(): boolean;
|
|
279
|
-
/**
|
|
280
|
-
* The `readable.unpipe()` method detaches a `Writable` stream previously attached
|
|
281
|
-
* using the {@link pipe} method.
|
|
282
|
-
*
|
|
283
|
-
* If the `destination` is not specified, then _all_ pipes are detached.
|
|
284
|
-
*
|
|
285
|
-
* If the `destination` is specified, but no pipe is set up for it, then
|
|
286
|
-
* the method does nothing.
|
|
287
|
-
*
|
|
288
|
-
* ```js
|
|
289
|
-
* const fs = require('fs');
|
|
290
|
-
* const readable = getReadableStreamSomehow();
|
|
291
|
-
* const writable = fs.createWriteStream('file.txt');
|
|
292
|
-
* // All the data from readable goes into 'file.txt',
|
|
293
|
-
* // but only for the first second.
|
|
294
|
-
* readable.pipe(writable);
|
|
295
|
-
* setTimeout(() => {
|
|
296
|
-
* console.log('Stop writing to file.txt.');
|
|
297
|
-
* readable.unpipe(writable);
|
|
298
|
-
* console.log('Manually close the file stream.');
|
|
299
|
-
* writable.end();
|
|
300
|
-
* }, 1000);
|
|
301
|
-
* ```
|
|
302
|
-
* @since v0.9.4
|
|
303
|
-
* @param destination Optional specific stream to unpipe
|
|
304
|
-
*/
|
|
305
|
-
unpipe(destination?: NodeJS.WritableStream): this;
|
|
306
|
-
/**
|
|
307
|
-
* Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
|
|
308
|
-
* same as `readable.push(null)`, after which no more data can be written. The EOF
|
|
309
|
-
* signal is put at the end of the buffer and any buffered data will still be
|
|
310
|
-
* flushed.
|
|
311
|
-
*
|
|
312
|
-
* The `readable.unshift()` method pushes a chunk of data back into the internal
|
|
313
|
-
* buffer. This is useful in certain situations where a stream is being consumed by
|
|
314
|
-
* code that needs to "un-consume" some amount of data that it has optimistically
|
|
315
|
-
* pulled out of the source, so that the data can be passed on to some other party.
|
|
316
|
-
*
|
|
317
|
-
* The `stream.unshift(chunk)` method cannot be called after the `'end'` event
|
|
318
|
-
* has been emitted or a runtime error will be thrown.
|
|
319
|
-
*
|
|
320
|
-
* Developers using `stream.unshift()` often should consider switching to
|
|
321
|
-
* use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
|
|
322
|
-
*
|
|
323
|
-
* ```js
|
|
324
|
-
* // Pull off a header delimited by \n\n.
|
|
325
|
-
* // Use unshift() if we get too much.
|
|
326
|
-
* // Call the callback with (error, header, stream).
|
|
327
|
-
* const { StringDecoder } = require('string_decoder');
|
|
328
|
-
* function parseHeader(stream, callback) {
|
|
329
|
-
* stream.on('error', callback);
|
|
330
|
-
* stream.on('readable', onReadable);
|
|
331
|
-
* const decoder = new StringDecoder('utf8');
|
|
332
|
-
* let header = '';
|
|
333
|
-
* function onReadable() {
|
|
334
|
-
* let chunk;
|
|
335
|
-
* while (null !== (chunk = stream.read())) {
|
|
336
|
-
* const str = decoder.write(chunk);
|
|
337
|
-
* if (str.match(/\n\n/)) {
|
|
338
|
-
* // Found the header boundary.
|
|
339
|
-
* const split = str.split(/\n\n/);
|
|
340
|
-
* header += split.shift();
|
|
341
|
-
* const remaining = split.join('\n\n');
|
|
342
|
-
* const buf = Buffer.from(remaining, 'utf8');
|
|
343
|
-
* stream.removeListener('error', callback);
|
|
344
|
-
* // Remove the 'readable' listener before unshifting.
|
|
345
|
-
* stream.removeListener('readable', onReadable);
|
|
346
|
-
* if (buf.length)
|
|
347
|
-
* stream.unshift(buf);
|
|
348
|
-
* // Now the body of the message can be read from the stream.
|
|
349
|
-
* callback(null, header, stream);
|
|
350
|
-
* } else {
|
|
351
|
-
* // Still reading the header.
|
|
352
|
-
* header += str;
|
|
353
|
-
* }
|
|
354
|
-
* }
|
|
355
|
-
* }
|
|
356
|
-
* }
|
|
357
|
-
* ```
|
|
358
|
-
*
|
|
359
|
-
* Unlike {@link push}, `stream.unshift(chunk)` will not
|
|
360
|
-
* end the reading process by resetting the internal reading state of the stream.
|
|
361
|
-
* This can cause unexpected results if `readable.unshift()` is called during a
|
|
362
|
-
* read (i.e. from within a {@link _read} implementation on a
|
|
363
|
-
* custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
|
|
364
|
-
* however it is best to simply avoid calling `readable.unshift()` while in the
|
|
365
|
-
* process of performing a read.
|
|
366
|
-
* @since v0.9.11
|
|
367
|
-
* @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer`, `Uint8Array` or `null`. For object mode
|
|
368
|
-
* streams, `chunk` may be any JavaScript value.
|
|
369
|
-
* @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
|
|
370
|
-
*/
|
|
371
|
-
unshift(chunk: any, encoding?: BufferEncoding): void;
|
|
372
|
-
/**
|
|
373
|
-
* Prior to Node.js 0.10, streams did not implement the entire `stream` module API
|
|
374
|
-
* as it is currently defined. (See `Compatibility` for more information.)
|
|
375
|
-
*
|
|
376
|
-
* When using an older Node.js library that emits `'data'` events and has a {@link pause} method that is advisory only, the`readable.wrap()` method can be used to create a `Readable`
|
|
377
|
-
* stream that uses
|
|
378
|
-
* the old stream as its data source.
|
|
379
|
-
*
|
|
380
|
-
* It will rarely be necessary to use `readable.wrap()` but the method has been
|
|
381
|
-
* provided as a convenience for interacting with older Node.js applications and
|
|
382
|
-
* libraries.
|
|
383
|
-
*
|
|
384
|
-
* ```js
|
|
385
|
-
* const { OldReader } = require('./old-api-module.js');
|
|
386
|
-
* const { Readable } = require('stream');
|
|
387
|
-
* const oreader = new OldReader();
|
|
388
|
-
* const myReader = new Readable().wrap(oreader);
|
|
389
|
-
*
|
|
390
|
-
* myReader.on('readable', () => {
|
|
391
|
-
* myReader.read(); // etc.
|
|
392
|
-
* });
|
|
393
|
-
* ```
|
|
394
|
-
* @since v0.9.4
|
|
395
|
-
* @param stream An "old style" readable stream
|
|
396
|
-
*/
|
|
397
|
-
wrap(stream: NodeJS.ReadableStream): this;
|
|
398
|
-
push(chunk: any, encoding?: BufferEncoding): boolean;
|
|
399
|
-
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
400
|
-
/**
|
|
401
|
-
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
|
|
402
|
-
* stream will release any internal resources and subsequent calls to `push()`will be ignored.
|
|
403
|
-
*
|
|
404
|
-
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
405
|
-
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
406
|
-
*
|
|
407
|
-
* Implementors should not override this method, but instead implement `readable._destroy()`.
|
|
408
|
-
* @since v8.0.0
|
|
409
|
-
* @param error Error which will be passed as payload in `'error'` event
|
|
410
|
-
*/
|
|
411
|
-
destroy(error?: Error): this;
|
|
412
|
-
/**
|
|
413
|
-
* Event emitter
|
|
414
|
-
* The defined events on documents including:
|
|
415
|
-
* 1. close
|
|
416
|
-
* 2. data
|
|
417
|
-
* 3. end
|
|
418
|
-
* 4. error
|
|
419
|
-
* 5. pause
|
|
420
|
-
* 6. readable
|
|
421
|
-
* 7. resume
|
|
422
|
-
*/
|
|
423
|
-
addListener(event: 'close', listener: () => void): this;
|
|
424
|
-
addListener(event: 'data', listener: (chunk: any) => void): this;
|
|
425
|
-
addListener(event: 'end', listener: () => void): this;
|
|
426
|
-
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
427
|
-
addListener(event: 'pause', listener: () => void): this;
|
|
428
|
-
addListener(event: 'readable', listener: () => void): this;
|
|
429
|
-
addListener(event: 'resume', listener: () => void): this;
|
|
430
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
431
|
-
emit(event: 'close'): boolean;
|
|
432
|
-
emit(event: 'data', chunk: any): boolean;
|
|
433
|
-
emit(event: 'end'): boolean;
|
|
434
|
-
emit(event: 'error', err: Error): boolean;
|
|
435
|
-
emit(event: 'pause'): boolean;
|
|
436
|
-
emit(event: 'readable'): boolean;
|
|
437
|
-
emit(event: 'resume'): boolean;
|
|
438
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
439
|
-
on(event: 'close', listener: () => void): this;
|
|
440
|
-
on(event: 'data', listener: (chunk: any) => void): this;
|
|
441
|
-
on(event: 'end', listener: () => void): this;
|
|
442
|
-
on(event: 'error', listener: (err: Error) => void): this;
|
|
443
|
-
on(event: 'pause', listener: () => void): this;
|
|
444
|
-
on(event: 'readable', listener: () => void): this;
|
|
445
|
-
on(event: 'resume', listener: () => void): this;
|
|
446
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
447
|
-
once(event: 'close', listener: () => void): this;
|
|
448
|
-
once(event: 'data', listener: (chunk: any) => void): this;
|
|
449
|
-
once(event: 'end', listener: () => void): this;
|
|
450
|
-
once(event: 'error', listener: (err: Error) => void): this;
|
|
451
|
-
once(event: 'pause', listener: () => void): this;
|
|
452
|
-
once(event: 'readable', listener: () => void): this;
|
|
453
|
-
once(event: 'resume', listener: () => void): this;
|
|
454
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
455
|
-
prependListener(event: 'close', listener: () => void): this;
|
|
456
|
-
prependListener(event: 'data', listener: (chunk: any) => void): this;
|
|
457
|
-
prependListener(event: 'end', listener: () => void): this;
|
|
458
|
-
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
459
|
-
prependListener(event: 'pause', listener: () => void): this;
|
|
460
|
-
prependListener(event: 'readable', listener: () => void): this;
|
|
461
|
-
prependListener(event: 'resume', listener: () => void): this;
|
|
462
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
463
|
-
prependOnceListener(event: 'close', listener: () => void): this;
|
|
464
|
-
prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
|
|
465
|
-
prependOnceListener(event: 'end', listener: () => void): this;
|
|
466
|
-
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
467
|
-
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
468
|
-
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
469
|
-
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
470
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
471
|
-
removeListener(event: 'close', listener: () => void): this;
|
|
472
|
-
removeListener(event: 'data', listener: (chunk: any) => void): this;
|
|
473
|
-
removeListener(event: 'end', listener: () => void): this;
|
|
474
|
-
removeListener(event: 'error', listener: (err: Error) => void): this;
|
|
475
|
-
removeListener(event: 'pause', listener: () => void): this;
|
|
476
|
-
removeListener(event: 'readable', listener: () => void): this;
|
|
477
|
-
removeListener(event: 'resume', listener: () => void): this;
|
|
478
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
479
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
|
797
|
+
static toWeb(streamReadable: Readable): streamWeb.ReadableStream;
|
|
480
798
|
}
|
|
481
799
|
interface WritableOptions extends StreamOptions<Writable> {
|
|
482
800
|
decodeStrings?: boolean | undefined;
|
|
483
801
|
defaultEncoding?: BufferEncoding | undefined;
|
|
484
802
|
write?(this: Writable, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
485
|
-
writev?(
|
|
486
|
-
this: Writable,
|
|
487
|
-
chunks: Array<{
|
|
488
|
-
chunk: any;
|
|
489
|
-
encoding: BufferEncoding;
|
|
490
|
-
}>,
|
|
491
|
-
callback: (error?: Error | null) => void
|
|
492
|
-
): void;
|
|
493
|
-
final?(this: Writable, callback: (error?: Error | null) => void): void;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* @since v0.9.4
|
|
497
|
-
*/
|
|
498
|
-
class Writable extends Stream implements NodeJS.WritableStream {
|
|
499
|
-
/**
|
|
500
|
-
* Is `true` if it is safe to call `writable.write()`, which means
|
|
501
|
-
* the stream has not been destroyed, errored or ended.
|
|
502
|
-
* @since v11.4.0
|
|
503
|
-
*/
|
|
504
|
-
readonly writable: boolean;
|
|
505
|
-
/**
|
|
506
|
-
* Is `true` after `writable.end()` has been called. This property
|
|
507
|
-
* does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
|
|
508
|
-
* @since v12.9.0
|
|
509
|
-
*/
|
|
510
|
-
readonly writableEnded: boolean;
|
|
511
|
-
/**
|
|
512
|
-
* Is set to `true` immediately before the `'finish'` event is emitted.
|
|
513
|
-
* @since v12.6.0
|
|
514
|
-
*/
|
|
515
|
-
readonly writableFinished: boolean;
|
|
516
|
-
/**
|
|
517
|
-
* Return the value of `highWaterMark` passed when creating this `Writable`.
|
|
518
|
-
* @since v9.3.0
|
|
519
|
-
*/
|
|
520
|
-
readonly writableHighWaterMark: number;
|
|
521
|
-
/**
|
|
522
|
-
* This property contains the number of bytes (or objects) in the queue
|
|
523
|
-
* ready to be written. The value provides introspection data regarding
|
|
524
|
-
* the status of the `highWaterMark`.
|
|
525
|
-
* @since v9.4.0
|
|
526
|
-
*/
|
|
527
|
-
readonly writableLength: number;
|
|
528
|
-
/**
|
|
529
|
-
* Getter for the property `objectMode` of a given `Writable` stream.
|
|
530
|
-
* @since v12.3.0
|
|
531
|
-
*/
|
|
532
|
-
readonly writableObjectMode: boolean;
|
|
533
|
-
/**
|
|
534
|
-
* Number of times `writable.uncork()` needs to be
|
|
535
|
-
* called in order to fully uncork the stream.
|
|
536
|
-
* @since v13.2.0, v12.16.0
|
|
537
|
-
*/
|
|
538
|
-
readonly writableCorked: number;
|
|
539
|
-
/**
|
|
540
|
-
* Is `true` after `writable.destroy()` has been called.
|
|
541
|
-
* @since v8.0.0
|
|
542
|
-
*/
|
|
543
|
-
destroyed: boolean;
|
|
544
|
-
constructor(opts?: WritableOptions);
|
|
545
|
-
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
546
|
-
_writev?(
|
|
803
|
+
writev?(
|
|
804
|
+
this: Writable,
|
|
547
805
|
chunks: Array<{
|
|
548
806
|
chunk: any;
|
|
549
807
|
encoding: BufferEncoding;
|
|
550
808
|
}>,
|
|
551
809
|
callback: (error?: Error | null) => void
|
|
552
810
|
): void;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
* occurs, the `callback` will be called with the error as its
|
|
560
|
-
* first argument. The `callback` is called asynchronously and before `'error'` is
|
|
561
|
-
* emitted.
|
|
562
|
-
*
|
|
563
|
-
* The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
|
|
564
|
-
* If `false` is returned, further attempts to write data to the stream should
|
|
565
|
-
* stop until the `'drain'` event is emitted.
|
|
566
|
-
*
|
|
567
|
-
* While a stream is not draining, calls to `write()` will buffer `chunk`, and
|
|
568
|
-
* return false. Once all currently buffered chunks are drained (accepted for
|
|
569
|
-
* delivery by the operating system), the `'drain'` event will be emitted.
|
|
570
|
-
* It is recommended that once `write()` returns false, no more chunks be written
|
|
571
|
-
* until the `'drain'` event is emitted. While calling `write()` on a stream that
|
|
572
|
-
* is not draining is allowed, Node.js will buffer all written chunks until
|
|
573
|
-
* maximum memory usage occurs, at which point it will abort unconditionally.
|
|
574
|
-
* Even before it aborts, high memory usage will cause poor garbage collector
|
|
575
|
-
* performance and high RSS (which is not typically released back to the system,
|
|
576
|
-
* even after the memory is no longer required). Since TCP sockets may never
|
|
577
|
-
* drain if the remote peer does not read the data, writing a socket that is
|
|
578
|
-
* not draining may lead to a remotely exploitable vulnerability.
|
|
579
|
-
*
|
|
580
|
-
* Writing data while the stream is not draining is particularly
|
|
581
|
-
* problematic for a `Transform`, because the `Transform` streams are paused
|
|
582
|
-
* by default until they are piped or a `'data'` or `'readable'` event handler
|
|
583
|
-
* is added.
|
|
584
|
-
*
|
|
585
|
-
* If the data to be written can be generated or fetched on demand, it is
|
|
586
|
-
* recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
|
|
587
|
-
* possible to respect backpressure and avoid memory issues using the `'drain'` event:
|
|
588
|
-
*
|
|
589
|
-
* ```js
|
|
590
|
-
* function write(data, cb) {
|
|
591
|
-
* if (!stream.write(data)) {
|
|
592
|
-
* stream.once('drain', cb);
|
|
593
|
-
* } else {
|
|
594
|
-
* process.nextTick(cb);
|
|
595
|
-
* }
|
|
596
|
-
* }
|
|
597
|
-
*
|
|
598
|
-
* // Wait for cb to be called before doing any other write.
|
|
599
|
-
* write('hello', () => {
|
|
600
|
-
* console.log('Write completed, do more writes now.');
|
|
601
|
-
* });
|
|
602
|
-
* ```
|
|
603
|
-
*
|
|
604
|
-
* A `Writable` stream in object mode will always ignore the `encoding` argument.
|
|
605
|
-
* @since v0.9.4
|
|
606
|
-
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
|
|
607
|
-
* JavaScript value other than `null`.
|
|
608
|
-
* @param [encoding='utf8'] The encoding, if `chunk` is a string.
|
|
609
|
-
* @param callback Callback for when this chunk of data is flushed.
|
|
610
|
-
* @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
|
|
611
|
-
*/
|
|
612
|
-
write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
|
|
613
|
-
write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
|
|
614
|
-
/**
|
|
615
|
-
* The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
|
|
616
|
-
* @since v0.11.15
|
|
617
|
-
* @param encoding The new default encoding
|
|
618
|
-
*/
|
|
619
|
-
setDefaultEncoding(encoding: BufferEncoding): this;
|
|
620
|
-
/**
|
|
621
|
-
* Calling the `writable.end()` method signals that no more data will be written
|
|
622
|
-
* to the `Writable`. The optional `chunk` and `encoding` arguments allow one
|
|
623
|
-
* final additional chunk of data to be written immediately before closing the
|
|
624
|
-
* stream.
|
|
625
|
-
*
|
|
626
|
-
* Calling the {@link write} method after calling {@link end} will raise an error.
|
|
627
|
-
*
|
|
628
|
-
* ```js
|
|
629
|
-
* // Write 'hello, ' and then end with 'world!'.
|
|
630
|
-
* const fs = require('fs');
|
|
631
|
-
* const file = fs.createWriteStream('example.txt');
|
|
632
|
-
* file.write('hello, ');
|
|
633
|
-
* file.end('world!');
|
|
634
|
-
* // Writing more now is not allowed!
|
|
635
|
-
* ```
|
|
636
|
-
* @since v0.9.4
|
|
637
|
-
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
|
|
638
|
-
* JavaScript value other than `null`.
|
|
639
|
-
* @param encoding The encoding if `chunk` is a string
|
|
640
|
-
* @param callback Callback for when the stream is finished.
|
|
641
|
-
*/
|
|
642
|
-
end(cb?: () => void): this;
|
|
643
|
-
end(chunk: any, cb?: () => void): this;
|
|
644
|
-
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
645
|
-
/**
|
|
646
|
-
* The `writable.cork()` method forces all written data to be buffered in memory.
|
|
647
|
-
* The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
|
|
648
|
-
*
|
|
649
|
-
* The primary intent of `writable.cork()` is to accommodate a situation in which
|
|
650
|
-
* several small chunks are written to the stream in rapid succession. Instead of
|
|
651
|
-
* immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
|
|
652
|
-
* all to `writable._writev()`, if present. This prevents a head-of-line blocking
|
|
653
|
-
* situation where data is being buffered while waiting for the first small chunk
|
|
654
|
-
* to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
|
|
655
|
-
*
|
|
656
|
-
* See also: `writable.uncork()`, `writable._writev()`.
|
|
657
|
-
* @since v0.11.2
|
|
658
|
-
*/
|
|
659
|
-
cork(): void;
|
|
660
|
-
/**
|
|
661
|
-
* The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
|
|
662
|
-
*
|
|
663
|
-
* When using `writable.cork()` and `writable.uncork()` to manage the buffering
|
|
664
|
-
* of writes to a stream, it is recommended that calls to `writable.uncork()` be
|
|
665
|
-
* deferred using `process.nextTick()`. Doing so allows batching of all`writable.write()` calls that occur within a given Node.js event loop phase.
|
|
666
|
-
*
|
|
667
|
-
* ```js
|
|
668
|
-
* stream.cork();
|
|
669
|
-
* stream.write('some ');
|
|
670
|
-
* stream.write('data ');
|
|
671
|
-
* process.nextTick(() => stream.uncork());
|
|
672
|
-
* ```
|
|
673
|
-
*
|
|
674
|
-
* If the `writable.cork()` method is called multiple times on a stream, the
|
|
675
|
-
* same number of calls to `writable.uncork()` must be called to flush the buffered
|
|
676
|
-
* data.
|
|
677
|
-
*
|
|
678
|
-
* ```js
|
|
679
|
-
* stream.cork();
|
|
680
|
-
* stream.write('some ');
|
|
681
|
-
* stream.cork();
|
|
682
|
-
* stream.write('data ');
|
|
683
|
-
* process.nextTick(() => {
|
|
684
|
-
* stream.uncork();
|
|
685
|
-
* // The data will not be flushed until uncork() is called a second time.
|
|
686
|
-
* stream.uncork();
|
|
687
|
-
* });
|
|
688
|
-
* ```
|
|
689
|
-
*
|
|
690
|
-
* See also: `writable.cork()`.
|
|
691
|
-
* @since v0.11.2
|
|
692
|
-
*/
|
|
693
|
-
uncork(): void;
|
|
811
|
+
final?(this: Writable, callback: (error?: Error | null) => void): void;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* @since v0.9.4
|
|
815
|
+
*/
|
|
816
|
+
class Writable extends WritableBase {
|
|
694
817
|
/**
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
* This is a destructive and immediate way to destroy a stream. Previous calls to`write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
|
|
699
|
-
* Use `end()` instead of destroy if data should flush before close, or wait for
|
|
700
|
-
* the `'drain'` event before destroying the stream.
|
|
701
|
-
*
|
|
702
|
-
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
703
|
-
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
704
|
-
*
|
|
705
|
-
* Implementors should not override this method,
|
|
706
|
-
* but instead implement `writable._destroy()`.
|
|
707
|
-
* @since v8.0.0
|
|
708
|
-
* @param error Optional, an error to emit with `'error'` event.
|
|
818
|
+
* A utility method for creating a `Writable` from a web `WritableStream`.
|
|
819
|
+
* @since v17.0.0
|
|
820
|
+
* @experimental
|
|
709
821
|
*/
|
|
710
|
-
|
|
822
|
+
static fromWeb(writableStream: streamWeb.WritableStream, options?: Pick<WritableOptions, 'decodeStrings' | 'highWaterMark' | 'objectMode' | 'signal'>): Writable;
|
|
711
823
|
/**
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
* 2. drain
|
|
716
|
-
* 3. error
|
|
717
|
-
* 4. finish
|
|
718
|
-
* 5. pipe
|
|
719
|
-
* 6. unpipe
|
|
824
|
+
* A utility method for creating a web `WritableStream` from a `Writable`.
|
|
825
|
+
* @since v17.0.0
|
|
826
|
+
* @experimental
|
|
720
827
|
*/
|
|
721
|
-
|
|
722
|
-
addListener(event: 'drain', listener: () => void): this;
|
|
723
|
-
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
724
|
-
addListener(event: 'finish', listener: () => void): this;
|
|
725
|
-
addListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
726
|
-
addListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
727
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
728
|
-
emit(event: 'close'): boolean;
|
|
729
|
-
emit(event: 'drain'): boolean;
|
|
730
|
-
emit(event: 'error', err: Error): boolean;
|
|
731
|
-
emit(event: 'finish'): boolean;
|
|
732
|
-
emit(event: 'pipe', src: Readable): boolean;
|
|
733
|
-
emit(event: 'unpipe', src: Readable): boolean;
|
|
734
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
735
|
-
on(event: 'close', listener: () => void): this;
|
|
736
|
-
on(event: 'drain', listener: () => void): this;
|
|
737
|
-
on(event: 'error', listener: (err: Error) => void): this;
|
|
738
|
-
on(event: 'finish', listener: () => void): this;
|
|
739
|
-
on(event: 'pipe', listener: (src: Readable) => void): this;
|
|
740
|
-
on(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
741
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
742
|
-
once(event: 'close', listener: () => void): this;
|
|
743
|
-
once(event: 'drain', listener: () => void): this;
|
|
744
|
-
once(event: 'error', listener: (err: Error) => void): this;
|
|
745
|
-
once(event: 'finish', listener: () => void): this;
|
|
746
|
-
once(event: 'pipe', listener: (src: Readable) => void): this;
|
|
747
|
-
once(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
748
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
749
|
-
prependListener(event: 'close', listener: () => void): this;
|
|
750
|
-
prependListener(event: 'drain', listener: () => void): this;
|
|
751
|
-
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
752
|
-
prependListener(event: 'finish', listener: () => void): this;
|
|
753
|
-
prependListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
754
|
-
prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
755
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
756
|
-
prependOnceListener(event: 'close', listener: () => void): this;
|
|
757
|
-
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
758
|
-
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
759
|
-
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
760
|
-
prependOnceListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
761
|
-
prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
762
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
763
|
-
removeListener(event: 'close', listener: () => void): this;
|
|
764
|
-
removeListener(event: 'drain', listener: () => void): this;
|
|
765
|
-
removeListener(event: 'error', listener: (err: Error) => void): this;
|
|
766
|
-
removeListener(event: 'finish', listener: () => void): this;
|
|
767
|
-
removeListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
768
|
-
removeListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
769
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
828
|
+
static toWeb(streamWritable: Writable): streamWeb.WritableStream;
|
|
770
829
|
}
|
|
771
830
|
interface DuplexOptions extends ReadableOptions, WritableOptions {
|
|
772
831
|
allowHalfOpen?: boolean | undefined;
|
|
@@ -799,7 +858,7 @@ declare module 'stream' {
|
|
|
799
858
|
* * `crypto streams`
|
|
800
859
|
* @since v0.9.4
|
|
801
860
|
*/
|
|
802
|
-
class Duplex extends
|
|
861
|
+
class Duplex extends ReadableBase implements WritableBase {
|
|
803
862
|
readonly writable: boolean;
|
|
804
863
|
readonly writableEnded: boolean;
|
|
805
864
|
readonly writableFinished: boolean;
|
|
@@ -807,10 +866,13 @@ declare module 'stream' {
|
|
|
807
866
|
readonly writableLength: number;
|
|
808
867
|
readonly writableObjectMode: boolean;
|
|
809
868
|
readonly writableCorked: number;
|
|
869
|
+
readonly writableNeedDrain: boolean;
|
|
870
|
+
readonly closed: boolean;
|
|
871
|
+
readonly errored: Error | null;
|
|
810
872
|
/**
|
|
811
873
|
* If `false` then the stream will automatically end the writable side when the
|
|
812
874
|
* readable side ends. Set initially by the `allowHalfOpen` constructor option,
|
|
813
|
-
* which defaults to `
|
|
875
|
+
* which defaults to `true`.
|
|
814
876
|
*
|
|
815
877
|
* This can be changed manually to change the half-open behavior of an existing`Duplex` stream instance, but must be changed before the `'end'` event is
|
|
816
878
|
* emitted.
|
|
@@ -839,7 +901,7 @@ declare module 'stream' {
|
|
|
839
901
|
*
|
|
840
902
|
* @since v16.8.0
|
|
841
903
|
*/
|
|
842
|
-
static from(src: Stream |
|
|
904
|
+
static from(src: Stream | NodeBlob | ArrayBuffer | string | Iterable<any> | AsyncIterable<any> | AsyncGeneratorFunction | Promise<any> | Object): Duplex;
|
|
843
905
|
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
844
906
|
_writev?(
|
|
845
907
|
chunks: Array<{
|
|
@@ -858,6 +920,126 @@ declare module 'stream' {
|
|
|
858
920
|
end(chunk: any, encoding?: BufferEncoding, cb?: () => void): this;
|
|
859
921
|
cork(): void;
|
|
860
922
|
uncork(): void;
|
|
923
|
+
/**
|
|
924
|
+
* A utility method for creating a web `ReadableStream` and `WritableStream` from a `Duplex`.
|
|
925
|
+
* @since v17.0.0
|
|
926
|
+
* @experimental
|
|
927
|
+
*/
|
|
928
|
+
static toWeb(streamDuplex: Duplex): {
|
|
929
|
+
readable: streamWeb.ReadableStream;
|
|
930
|
+
writable: streamWeb.WritableStream;
|
|
931
|
+
};
|
|
932
|
+
/**
|
|
933
|
+
* A utility method for creating a `Duplex` from a web `ReadableStream` and `WritableStream`.
|
|
934
|
+
* @since v17.0.0
|
|
935
|
+
* @experimental
|
|
936
|
+
*/
|
|
937
|
+
static fromWeb(
|
|
938
|
+
duplexStream: {
|
|
939
|
+
readable: streamWeb.ReadableStream;
|
|
940
|
+
writable: streamWeb.WritableStream;
|
|
941
|
+
},
|
|
942
|
+
options?: Pick<DuplexOptions, 'allowHalfOpen' | 'decodeStrings' | 'encoding' | 'highWaterMark' | 'objectMode' | 'signal'>
|
|
943
|
+
): Duplex;
|
|
944
|
+
/**
|
|
945
|
+
* Event emitter
|
|
946
|
+
* The defined events on documents including:
|
|
947
|
+
* 1. close
|
|
948
|
+
* 2. data
|
|
949
|
+
* 3. drain
|
|
950
|
+
* 4. end
|
|
951
|
+
* 5. error
|
|
952
|
+
* 6. finish
|
|
953
|
+
* 7. pause
|
|
954
|
+
* 8. pipe
|
|
955
|
+
* 9. readable
|
|
956
|
+
* 10. resume
|
|
957
|
+
* 11. unpipe
|
|
958
|
+
*/
|
|
959
|
+
addListener(event: 'close', listener: () => void): this;
|
|
960
|
+
addListener(event: 'data', listener: (chunk: any) => void): this;
|
|
961
|
+
addListener(event: 'drain', listener: () => void): this;
|
|
962
|
+
addListener(event: 'end', listener: () => void): this;
|
|
963
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
964
|
+
addListener(event: 'finish', listener: () => void): this;
|
|
965
|
+
addListener(event: 'pause', listener: () => void): this;
|
|
966
|
+
addListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
967
|
+
addListener(event: 'readable', listener: () => void): this;
|
|
968
|
+
addListener(event: 'resume', listener: () => void): this;
|
|
969
|
+
addListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
970
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
971
|
+
emit(event: 'close'): boolean;
|
|
972
|
+
emit(event: 'data', chunk: any): boolean;
|
|
973
|
+
emit(event: 'drain'): boolean;
|
|
974
|
+
emit(event: 'end'): boolean;
|
|
975
|
+
emit(event: 'error', err: Error): boolean;
|
|
976
|
+
emit(event: 'finish'): boolean;
|
|
977
|
+
emit(event: 'pause'): boolean;
|
|
978
|
+
emit(event: 'pipe', src: Readable): boolean;
|
|
979
|
+
emit(event: 'readable'): boolean;
|
|
980
|
+
emit(event: 'resume'): boolean;
|
|
981
|
+
emit(event: 'unpipe', src: Readable): boolean;
|
|
982
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
983
|
+
on(event: 'close', listener: () => void): this;
|
|
984
|
+
on(event: 'data', listener: (chunk: any) => void): this;
|
|
985
|
+
on(event: 'drain', listener: () => void): this;
|
|
986
|
+
on(event: 'end', listener: () => void): this;
|
|
987
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
988
|
+
on(event: 'finish', listener: () => void): this;
|
|
989
|
+
on(event: 'pause', listener: () => void): this;
|
|
990
|
+
on(event: 'pipe', listener: (src: Readable) => void): this;
|
|
991
|
+
on(event: 'readable', listener: () => void): this;
|
|
992
|
+
on(event: 'resume', listener: () => void): this;
|
|
993
|
+
on(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
994
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
995
|
+
once(event: 'close', listener: () => void): this;
|
|
996
|
+
once(event: 'data', listener: (chunk: any) => void): this;
|
|
997
|
+
once(event: 'drain', listener: () => void): this;
|
|
998
|
+
once(event: 'end', listener: () => void): this;
|
|
999
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
1000
|
+
once(event: 'finish', listener: () => void): this;
|
|
1001
|
+
once(event: 'pause', listener: () => void): this;
|
|
1002
|
+
once(event: 'pipe', listener: (src: Readable) => void): this;
|
|
1003
|
+
once(event: 'readable', listener: () => void): this;
|
|
1004
|
+
once(event: 'resume', listener: () => void): this;
|
|
1005
|
+
once(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
1006
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1007
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
1008
|
+
prependListener(event: 'data', listener: (chunk: any) => void): this;
|
|
1009
|
+
prependListener(event: 'drain', listener: () => void): this;
|
|
1010
|
+
prependListener(event: 'end', listener: () => void): this;
|
|
1011
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
1012
|
+
prependListener(event: 'finish', listener: () => void): this;
|
|
1013
|
+
prependListener(event: 'pause', listener: () => void): this;
|
|
1014
|
+
prependListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
1015
|
+
prependListener(event: 'readable', listener: () => void): this;
|
|
1016
|
+
prependListener(event: 'resume', listener: () => void): this;
|
|
1017
|
+
prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
1018
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1019
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
1020
|
+
prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
|
|
1021
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
1022
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
|
1023
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
1024
|
+
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
1025
|
+
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
1026
|
+
prependOnceListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
1027
|
+
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
1028
|
+
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
1029
|
+
prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
1030
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1031
|
+
removeListener(event: 'close', listener: () => void): this;
|
|
1032
|
+
removeListener(event: 'data', listener: (chunk: any) => void): this;
|
|
1033
|
+
removeListener(event: 'drain', listener: () => void): this;
|
|
1034
|
+
removeListener(event: 'end', listener: () => void): this;
|
|
1035
|
+
removeListener(event: 'error', listener: (err: Error) => void): this;
|
|
1036
|
+
removeListener(event: 'finish', listener: () => void): this;
|
|
1037
|
+
removeListener(event: 'pause', listener: () => void): this;
|
|
1038
|
+
removeListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
1039
|
+
removeListener(event: 'readable', listener: () => void): this;
|
|
1040
|
+
removeListener(event: 'resume', listener: () => void): this;
|
|
1041
|
+
removeListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
1042
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
861
1043
|
}
|
|
862
1044
|
type TransformCallback = (error?: Error | null, data?: any) => void;
|
|
863
1045
|
interface TransformOptions extends DuplexOptions {
|
|
@@ -899,18 +1081,21 @@ declare module 'stream' {
|
|
|
899
1081
|
*/
|
|
900
1082
|
class PassThrough extends Transform {}
|
|
901
1083
|
/**
|
|
1084
|
+
* A stream to attach a signal to.
|
|
1085
|
+
*
|
|
902
1086
|
* Attaches an AbortSignal to a readable or writeable stream. This lets code
|
|
903
1087
|
* control stream destruction using an `AbortController`.
|
|
904
1088
|
*
|
|
905
|
-
* Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the stream.
|
|
1089
|
+
* Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the stream, and `controller.error(new
|
|
1090
|
+
* AbortError())` for webstreams.
|
|
906
1091
|
*
|
|
907
1092
|
* ```js
|
|
908
|
-
* const fs = require('fs');
|
|
1093
|
+
* const fs = require('node:fs');
|
|
909
1094
|
*
|
|
910
1095
|
* const controller = new AbortController();
|
|
911
1096
|
* const read = addAbortSignal(
|
|
912
1097
|
* controller.signal,
|
|
913
|
-
* fs.createReadStream(('object.json'))
|
|
1098
|
+
* fs.createReadStream(('object.json')),
|
|
914
1099
|
* );
|
|
915
1100
|
* // Later, abort the operation closing the stream
|
|
916
1101
|
* controller.abort();
|
|
@@ -923,7 +1108,7 @@ declare module 'stream' {
|
|
|
923
1108
|
* setTimeout(() => controller.abort(), 10_000); // set a timeout
|
|
924
1109
|
* const stream = addAbortSignal(
|
|
925
1110
|
* controller.signal,
|
|
926
|
-
* fs.createReadStream(('object.json'))
|
|
1111
|
+
* fs.createReadStream(('object.json')),
|
|
927
1112
|
* );
|
|
928
1113
|
* (async () => {
|
|
929
1114
|
* try {
|
|
@@ -939,22 +1124,70 @@ declare module 'stream' {
|
|
|
939
1124
|
* }
|
|
940
1125
|
* })();
|
|
941
1126
|
* ```
|
|
1127
|
+
*
|
|
1128
|
+
* Or using an `AbortSignal` with a ReadableStream:
|
|
1129
|
+
*
|
|
1130
|
+
* ```js
|
|
1131
|
+
* const controller = new AbortController();
|
|
1132
|
+
* const rs = new ReadableStream({
|
|
1133
|
+
* start(controller) {
|
|
1134
|
+
* controller.enqueue('hello');
|
|
1135
|
+
* controller.enqueue('world');
|
|
1136
|
+
* controller.close();
|
|
1137
|
+
* },
|
|
1138
|
+
* });
|
|
1139
|
+
*
|
|
1140
|
+
* addAbortSignal(controller.signal, rs);
|
|
1141
|
+
*
|
|
1142
|
+
* finished(rs, (err) => {
|
|
1143
|
+
* if (err) {
|
|
1144
|
+
* if (err.name === 'AbortError') {
|
|
1145
|
+
* // The operation was cancelled
|
|
1146
|
+
* }
|
|
1147
|
+
* }
|
|
1148
|
+
* });
|
|
1149
|
+
*
|
|
1150
|
+
* const reader = rs.getReader();
|
|
1151
|
+
*
|
|
1152
|
+
* reader.read().then(({ value, done }) => {
|
|
1153
|
+
* console.log(value); // hello
|
|
1154
|
+
* console.log(done); // false
|
|
1155
|
+
* controller.abort();
|
|
1156
|
+
* });
|
|
1157
|
+
* ```
|
|
942
1158
|
* @since v15.4.0
|
|
943
1159
|
* @param signal A signal representing possible cancellation
|
|
944
1160
|
* @param stream a stream to attach a signal to
|
|
945
1161
|
*/
|
|
946
1162
|
function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
|
|
1163
|
+
/**
|
|
1164
|
+
* Returns the default highWaterMark used by streams.
|
|
1165
|
+
* Defaults to `16384` (16 KiB), or `16` for `objectMode`.
|
|
1166
|
+
* @since v19.9.0
|
|
1167
|
+
* @param objectMode
|
|
1168
|
+
*/
|
|
1169
|
+
function getDefaultHighWaterMark(objectMode: boolean): number;
|
|
1170
|
+
/**
|
|
1171
|
+
* Sets the default highWaterMark used by streams.
|
|
1172
|
+
* @since v19.9.0
|
|
1173
|
+
* @param objectMode
|
|
1174
|
+
* @param value highWaterMark value
|
|
1175
|
+
*/
|
|
1176
|
+
function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
|
|
947
1177
|
interface FinishedOptions extends Abortable {
|
|
948
1178
|
error?: boolean | undefined;
|
|
949
1179
|
readable?: boolean | undefined;
|
|
950
1180
|
writable?: boolean | undefined;
|
|
951
1181
|
}
|
|
952
1182
|
/**
|
|
1183
|
+
* A readable and/or writable stream/webstream.
|
|
1184
|
+
*
|
|
953
1185
|
* A function to get notified when a stream is no longer readable, writable
|
|
954
1186
|
* or has experienced an error or a premature close event.
|
|
955
1187
|
*
|
|
956
1188
|
* ```js
|
|
957
|
-
* const { finished } = require('stream');
|
|
1189
|
+
* const { finished } = require('node:stream');
|
|
1190
|
+
* const fs = require('node:fs');
|
|
958
1191
|
*
|
|
959
1192
|
* const rs = fs.createReadStream('archive.tar');
|
|
960
1193
|
*
|
|
@@ -972,21 +1205,7 @@ declare module 'stream' {
|
|
|
972
1205
|
* Especially useful in error handling scenarios where a stream is destroyed
|
|
973
1206
|
* prematurely (like an aborted HTTP request), and will not emit `'end'`or `'finish'`.
|
|
974
1207
|
*
|
|
975
|
-
* The `finished` API provides promise version
|
|
976
|
-
*
|
|
977
|
-
* ```js
|
|
978
|
-
* const { finished } = require('stream/promises');
|
|
979
|
-
*
|
|
980
|
-
* const rs = fs.createReadStream('archive.tar');
|
|
981
|
-
*
|
|
982
|
-
* async function run() {
|
|
983
|
-
* await finished(rs);
|
|
984
|
-
* console.log('Stream is done reading.');
|
|
985
|
-
* }
|
|
986
|
-
*
|
|
987
|
-
* run().catch(console.error);
|
|
988
|
-
* rs.resume(); // Drain the stream.
|
|
989
|
-
* ```
|
|
1208
|
+
* The `finished` API provides `promise version`.
|
|
990
1209
|
*
|
|
991
1210
|
* `stream.finished()` leaves dangling event listeners (in particular`'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
|
|
992
1211
|
* invoked. The reason for this is so that unexpected `'error'` events (due to
|
|
@@ -1026,16 +1245,17 @@ declare module 'stream' {
|
|
|
1026
1245
|
: (err: NodeJS.ErrnoException | null) => void;
|
|
1027
1246
|
type PipelinePromise<S extends PipelineDestination<any, any>> = S extends PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>;
|
|
1028
1247
|
interface PipelineOptions {
|
|
1029
|
-
signal
|
|
1248
|
+
signal?: AbortSignal | undefined;
|
|
1249
|
+
end?: boolean | undefined;
|
|
1030
1250
|
}
|
|
1031
1251
|
/**
|
|
1032
1252
|
* A module method to pipe between streams and generators forwarding errors and
|
|
1033
1253
|
* properly cleaning up and provide a callback when the pipeline is complete.
|
|
1034
1254
|
*
|
|
1035
1255
|
* ```js
|
|
1036
|
-
* const { pipeline } = require('stream');
|
|
1037
|
-
* const fs = require('fs');
|
|
1038
|
-
* const zlib = require('zlib');
|
|
1256
|
+
* const { pipeline } = require('node:stream');
|
|
1257
|
+
* const fs = require('node:fs');
|
|
1258
|
+
* const zlib = require('node:zlib');
|
|
1039
1259
|
*
|
|
1040
1260
|
* // Use the pipeline API to easily pipe a series of streams
|
|
1041
1261
|
* // together and get notified when the pipeline is fully done.
|
|
@@ -1052,95 +1272,11 @@ declare module 'stream' {
|
|
|
1052
1272
|
* } else {
|
|
1053
1273
|
* console.log('Pipeline succeeded.');
|
|
1054
1274
|
* }
|
|
1055
|
-
* }
|
|
1275
|
+
* },
|
|
1056
1276
|
* );
|
|
1057
1277
|
* ```
|
|
1058
1278
|
*
|
|
1059
|
-
* The `pipeline` API provides a promise version
|
|
1060
|
-
* receive an options argument as the last parameter with a`signal` `AbortSignal` property. When the signal is aborted,`destroy` will be called on the underlying pipeline, with
|
|
1061
|
-
* an`AbortError`.
|
|
1062
|
-
*
|
|
1063
|
-
* ```js
|
|
1064
|
-
* const { pipeline } = require('stream/promises');
|
|
1065
|
-
*
|
|
1066
|
-
* async function run() {
|
|
1067
|
-
* await pipeline(
|
|
1068
|
-
* fs.createReadStream('archive.tar'),
|
|
1069
|
-
* zlib.createGzip(),
|
|
1070
|
-
* fs.createWriteStream('archive.tar.gz')
|
|
1071
|
-
* );
|
|
1072
|
-
* console.log('Pipeline succeeded.');
|
|
1073
|
-
* }
|
|
1074
|
-
*
|
|
1075
|
-
* run().catch(console.error);
|
|
1076
|
-
* ```
|
|
1077
|
-
*
|
|
1078
|
-
* To use an `AbortSignal`, pass it inside an options object,
|
|
1079
|
-
* as the last argument:
|
|
1080
|
-
*
|
|
1081
|
-
* ```js
|
|
1082
|
-
* const { pipeline } = require('stream/promises');
|
|
1083
|
-
*
|
|
1084
|
-
* async function run() {
|
|
1085
|
-
* const ac = new AbortController();
|
|
1086
|
-
* const signal = ac.signal;
|
|
1087
|
-
*
|
|
1088
|
-
* setTimeout(() => ac.abort(), 1);
|
|
1089
|
-
* await pipeline(
|
|
1090
|
-
* fs.createReadStream('archive.tar'),
|
|
1091
|
-
* zlib.createGzip(),
|
|
1092
|
-
* fs.createWriteStream('archive.tar.gz'),
|
|
1093
|
-
* { signal },
|
|
1094
|
-
* );
|
|
1095
|
-
* }
|
|
1096
|
-
*
|
|
1097
|
-
* run().catch(console.error); // AbortError
|
|
1098
|
-
* ```
|
|
1099
|
-
*
|
|
1100
|
-
* The `pipeline` API also supports async generators:
|
|
1101
|
-
*
|
|
1102
|
-
* ```js
|
|
1103
|
-
* const { pipeline } = require('stream/promises');
|
|
1104
|
-
* const fs = require('fs');
|
|
1105
|
-
*
|
|
1106
|
-
* async function run() {
|
|
1107
|
-
* await pipeline(
|
|
1108
|
-
* fs.createReadStream('lowercase.txt'),
|
|
1109
|
-
* async function* (source, signal) {
|
|
1110
|
-
* source.setEncoding('utf8'); // Work with strings rather than `Buffer`s.
|
|
1111
|
-
* for await (const chunk of source) {
|
|
1112
|
-
* yield await processChunk(chunk, { signal });
|
|
1113
|
-
* }
|
|
1114
|
-
* },
|
|
1115
|
-
* fs.createWriteStream('uppercase.txt')
|
|
1116
|
-
* );
|
|
1117
|
-
* console.log('Pipeline succeeded.');
|
|
1118
|
-
* }
|
|
1119
|
-
*
|
|
1120
|
-
* run().catch(console.error);
|
|
1121
|
-
* ```
|
|
1122
|
-
*
|
|
1123
|
-
* Remember to handle the `signal` argument passed into the async generator.
|
|
1124
|
-
* Especially in the case where the async generator is the source for the
|
|
1125
|
-
* pipeline (i.e. first argument) or the pipeline will never complete.
|
|
1126
|
-
*
|
|
1127
|
-
* ```js
|
|
1128
|
-
* const { pipeline } = require('stream/promises');
|
|
1129
|
-
* const fs = require('fs');
|
|
1130
|
-
*
|
|
1131
|
-
* async function run() {
|
|
1132
|
-
* await pipeline(
|
|
1133
|
-
* async function * (signal) {
|
|
1134
|
-
* await someLongRunningfn({ signal });
|
|
1135
|
-
* yield 'asd';
|
|
1136
|
-
* },
|
|
1137
|
-
* fs.createWriteStream('uppercase.txt')
|
|
1138
|
-
* );
|
|
1139
|
-
* console.log('Pipeline succeeded.');
|
|
1140
|
-
* }
|
|
1141
|
-
*
|
|
1142
|
-
* run().catch(console.error);
|
|
1143
|
-
* ```
|
|
1279
|
+
* The `pipeline` API provides a `promise version`.
|
|
1144
1280
|
*
|
|
1145
1281
|
* `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
|
|
1146
1282
|
*
|
|
@@ -1149,7 +1285,31 @@ declare module 'stream' {
|
|
|
1149
1285
|
*
|
|
1150
1286
|
* `stream.pipeline()` leaves dangling event listeners on the streams
|
|
1151
1287
|
* after the `callback` has been invoked. In the case of reuse of streams after
|
|
1152
|
-
* failure, this can cause event listener leaks and swallowed errors.
|
|
1288
|
+
* failure, this can cause event listener leaks and swallowed errors. If the last
|
|
1289
|
+
* stream is readable, dangling event listeners will be removed so that the last
|
|
1290
|
+
* stream can be consumed later.
|
|
1291
|
+
*
|
|
1292
|
+
* `stream.pipeline()` closes all the streams when an error is raised.
|
|
1293
|
+
* The `IncomingRequest` usage with `pipeline` could lead to an unexpected behavior
|
|
1294
|
+
* once it would destroy the socket without sending the expected response.
|
|
1295
|
+
* See the example below:
|
|
1296
|
+
*
|
|
1297
|
+
* ```js
|
|
1298
|
+
* const fs = require('node:fs');
|
|
1299
|
+
* const http = require('node:http');
|
|
1300
|
+
* const { pipeline } = require('node:stream');
|
|
1301
|
+
*
|
|
1302
|
+
* const server = http.createServer((req, res) => {
|
|
1303
|
+
* const fileStream = fs.createReadStream('./fileNotExist.txt');
|
|
1304
|
+
* pipeline(fileStream, res, (err) => {
|
|
1305
|
+
* if (err) {
|
|
1306
|
+
* console.log(err); // No such file
|
|
1307
|
+
* // this message can't be sent once `pipeline` already destroyed the socket
|
|
1308
|
+
* return res.end('error!!!');
|
|
1309
|
+
* }
|
|
1310
|
+
* });
|
|
1311
|
+
* });
|
|
1312
|
+
* ```
|
|
1153
1313
|
* @since v10.0.0
|
|
1154
1314
|
* @param callback Called when the pipeline is fully done.
|
|
1155
1315
|
*/
|
|
@@ -1238,19 +1398,18 @@ declare module 'stream' {
|
|
|
1238
1398
|
ref(): void;
|
|
1239
1399
|
unref(): void;
|
|
1240
1400
|
}
|
|
1241
|
-
|
|
1242
1401
|
/**
|
|
1243
1402
|
* Returns whether the stream has encountered an error.
|
|
1244
|
-
* @since v17.3.0
|
|
1403
|
+
* @since v17.3.0, v16.14.0
|
|
1404
|
+
* @experimental
|
|
1245
1405
|
*/
|
|
1246
1406
|
function isErrored(stream: Readable | Writable | NodeJS.ReadableStream | NodeJS.WritableStream): boolean;
|
|
1247
|
-
|
|
1248
1407
|
/**
|
|
1249
1408
|
* Returns whether the stream is readable.
|
|
1250
|
-
* @since v17.4.0
|
|
1409
|
+
* @since v17.4.0, v16.14.0
|
|
1410
|
+
* @experimental
|
|
1251
1411
|
*/
|
|
1252
1412
|
function isReadable(stream: Readable | NodeJS.ReadableStream): boolean;
|
|
1253
|
-
|
|
1254
1413
|
const promises: typeof streamPromises;
|
|
1255
1414
|
const consumers: typeof streamConsumers;
|
|
1256
1415
|
}
|