visaljs 0.0.7 → 0.0.9
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/README.md +68 -4
- package/THIRD_PARTY_LICENSES +1216 -0
- package/cli.js +4461 -321
- package/node/include/js_node.h +57 -1
- package/node/include/js_uv.h +8 -1
- package/node/prelude/_http_agent.js +5 -0
- package/node/prelude/_http_server.js +7 -0
- package/node/prelude/_stream_duplex.js +4 -0
- package/node/prelude/_stream_passthrough.js +4 -0
- package/node/prelude/_stream_readable.js +4 -0
- package/node/prelude/_stream_transform.js +4 -0
- package/node/prelude/_stream_writable.js +4 -0
- package/node/prelude/assert.js +1334 -0
- package/node/prelude/assert_strict.js +12 -0
- package/node/prelude/async_hooks.js +1 -1
- package/node/prelude/buffer.js +43 -3
- package/node/prelude/child_process.js +1098 -0
- package/node/prelude/cluster.js +52 -0
- package/node/prelude/console.js +328 -0
- package/node/prelude/constants.js +10 -0
- package/node/prelude/crypto.js +1 -1
- package/node/prelude/diagnostics_channel.js +1 -1
- package/node/prelude/dns.js +8 -2
- package/node/prelude/domain.js +115 -0
- package/node/prelude/events.js +148 -16
- package/node/prelude/fs.js +1138 -151
- package/node/prelude/fs_promises.js +117 -11
- package/node/prelude/http.js +784 -301
- package/node/prelude/http2.js +1 -1
- package/node/prelude/https.js +159 -0
- package/node/prelude/inspector.js +27 -0
- package/node/prelude/inspector_promises.js +4 -0
- package/node/prelude/internal/async_context.js +1 -1
- package/node/prelude/internal/buffer_transcode.js +44 -0
- package/node/prelude/internal/comparisons.js +916 -0
- package/node/prelude/internal/compression_streams.js +153 -0
- package/node/prelude/internal/crypto/asym.js +27 -14
- package/node/prelude/internal/crypto/cipher.js +16 -5
- package/node/prelude/internal/crypto/diffiehellman.js +3 -2
- package/node/prelude/internal/crypto/hash.js +2 -1
- package/node/prelude/internal/crypto/kdf.js +14 -9
- package/node/prelude/internal/crypto/keys.js +63 -50
- package/node/prelude/internal/crypto/random.js +2 -1
- package/node/prelude/internal/crypto/util.js +4 -4
- package/node/prelude/internal/dotenv.js +98 -0
- package/node/prelude/internal/errors.js +21 -5
- package/node/prelude/internal/events_extras.js +113 -0
- package/node/prelude/internal/events_on.js +100 -0
- package/node/prelude/internal/features.js +72 -0
- package/node/prelude/internal/fetch.js +364 -0
- package/node/prelude/internal/form_data.js +376 -0
- package/node/prelude/internal/fs_bigint_stats.js +41 -0
- package/node/prelude/internal/fs_blob.js +19 -0
- package/node/prelude/internal/fs_cp.js +709 -0
- package/node/prelude/internal/fs_dir.js +166 -0
- package/node/prelude/internal/fs_filehandle.js +287 -0
- package/node/prelude/internal/fs_glob.js +296 -0
- package/node/prelude/internal/fs_statfs.js +42 -0
- package/node/prelude/internal/fs_stats.js +89 -0
- package/node/prelude/internal/fs_streams.js +541 -0
- package/node/prelude/internal/fs_utils.js +286 -0
- package/node/prelude/internal/fs_watch.js +580 -0
- package/node/prelude/internal/http_agent.js +114 -2
- package/node/prelude/internal/http_symbols.js +3 -0
- package/node/prelude/internal/mime.js +249 -0
- package/node/prelude/internal/net.js +1 -0
- package/node/prelude/internal/net_bound.js +123 -0
- package/node/prelude/internal/net_onread.js +73 -0
- package/node/prelude/internal/net_tos.js +54 -0
- package/node/prelude/internal/parse_args.js +288 -0
- package/node/prelude/internal/perf_histogram.js +435 -0
- package/node/prelude/internal/perf_observe.js +125 -0
- package/node/prelude/internal/performance_global.js +19 -0
- package/node/prelude/internal/process_events.js +49 -1
- package/node/prelude/internal/process_memory.js +14 -0
- package/node/prelude/internal/process_more.js +414 -0
- package/node/prelude/internal/process_signals.js +2 -1
- package/node/prelude/internal/process_stdin.js +52 -0
- package/node/prelude/internal/process_stdio.js +36 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/readline.js +338 -0
- package/node/prelude/internal/socketaddress.js +8 -4
- package/node/prelude/internal/source_map.js +122 -0
- package/node/prelude/internal/stream_compose.js +74 -0
- package/node/prelude/internal/stream_from.js +6 -0
- package/node/prelude/internal/stream_operators.js +23 -0
- package/node/prelude/internal/stream_pipeline.js +7 -0
- package/node/prelude/internal/stream_transform.js +10 -0
- package/node/prelude/internal/stream_web_adapters.js +143 -0
- package/node/prelude/internal/streams/add_abort_signal.js +58 -0
- package/node/prelude/internal/streams/compose.js +244 -0
- package/node/prelude/internal/streams/destroy.js +358 -0
- package/node/prelude/internal/streams/duplex.js +199 -0
- package/node/prelude/internal/streams/duplexify.js +378 -0
- package/node/prelude/internal/streams/end_of_stream.js +387 -0
- package/node/prelude/internal/streams/errors.js +216 -0
- package/node/prelude/internal/streams/from.js +211 -0
- package/node/prelude/internal/streams/legacy.js +120 -0
- package/node/prelude/internal/streams/operators.js +375 -0
- package/node/prelude/internal/streams/passthrough.js +45 -0
- package/node/prelude/internal/streams/pipeline.js +468 -0
- package/node/prelude/internal/streams/readable.js +1835 -0
- package/node/prelude/internal/streams/state.js +48 -0
- package/node/prelude/internal/streams/transform.js +203 -0
- package/node/prelude/internal/streams/utils.js +355 -0
- package/node/prelude/internal/streams/validators.js +108 -0
- package/node/prelude/internal/streams/writable.js +1160 -0
- package/node/prelude/internal/structured_clone.js +238 -0
- package/node/prelude/internal/system_errors.js +37 -0
- package/node/prelude/internal/test_runner/mock.js +431 -0
- package/node/prelude/internal/test_runner/reporters.js +404 -0
- package/node/prelude/internal/test_runner/test.js +1571 -0
- package/node/prelude/internal/timers.js +38 -7
- package/node/prelude/internal/timers_global.js +1 -1
- package/node/prelude/internal/tls/common.js +8 -2
- package/node/prelude/internal/tls/wrap.js +5 -16
- package/node/prelude/internal/tls/x509.js +1 -1
- package/node/prelude/internal/tty_read_stream.js +39 -0
- package/node/prelude/internal/tty_streams.js +3 -0
- package/node/prelude/internal/util_debuglog.js +68 -0
- package/node/prelude/internal/util_diff.js +63 -0
- package/node/prelude/internal/util_more.js +111 -0
- package/node/prelude/internal/util_styles.js +76 -0
- package/node/prelude/internal/zlib_engines.js +1 -1
- package/node/prelude/module.js +219 -8
- package/node/prelude/net.js +197 -49
- package/node/prelude/os.js +88 -11
- package/node/prelude/path.js +11 -7
- package/node/prelude/path_posix.js +1 -1
- package/node/prelude/path_win32.js +1 -1
- package/node/prelude/perf_hooks.js +151 -0
- package/node/prelude/process.js +36 -1
- package/node/prelude/punycode.js +188 -0
- package/node/prelude/querystring.js +1 -1
- package/node/prelude/readline.js +8 -0
- package/node/prelude/readline_promises.js +88 -0
- package/node/prelude/repl.js +38 -0
- package/node/prelude/sea.js +23 -0
- package/node/prelude/stream.js +70 -1332
- package/node/prelude/stream_consumers.js +34 -0
- package/node/prelude/stream_promises.js +1 -1
- package/node/prelude/stream_web.js +15 -2
- package/node/prelude/string_decoder.js +1 -1
- package/node/prelude/sys.js +7 -0
- package/node/prelude/test.js +56 -0
- package/node/prelude/test_reporters.js +269 -0
- package/node/prelude/timers.js +7 -84
- package/node/prelude/timers_promises.js +1 -1
- package/node/prelude/tls.js +2 -1
- package/node/prelude/trace_events.js +52 -0
- package/node/prelude/tty.js +10 -4
- package/node/prelude/url.js +88 -27
- package/node/prelude/util.js +121 -5
- package/node/prelude/util_types.js +4 -3
- package/node/prelude/v8.js +814 -0
- package/node/prelude/vm.js +86 -0
- package/node/prelude/wasi.js +10 -0
- package/node/prelude/worker_threads.js +56 -0
- package/node/prelude/zlib.js +58 -25
- package/node/src/host_brotli.c +59 -11
- package/node/src/host_fs.c +342 -11
- package/node/src/host_fswatch.c +170 -0
- package/node/src/host_http.c +292 -39
- package/node/src/host_loop.c +25 -2
- package/node/src/host_net.c +130 -16
- package/node/src/host_os.c +55 -1
- package/node/src/host_proc.c +291 -0
- package/node/src/host_process.c +488 -0
- package/node/src/host_sys.c +64 -2
- package/node/src/host_zlib.c +27 -7
- package/node/src/host_zstd.c +41 -6
- package/node/third_party/hdrhistogram/LICENSE +42 -0
- package/node/third_party/hdrhistogram/README.md +5 -0
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/LICENSE-extra +36 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/node/third_party/nodejs/LICENSE +47 -0
- package/node/third_party/nodejs/README.md +5 -0
- package/node/third_party/parseargs/LICENSE +21 -0
- package/node/third_party/parseargs/README.md +5 -0
- package/node/third_party/punycode/LICENSE +20 -0
- package/node/third_party/punycode/README.md +5 -0
- package/node/third_party/zlib/LICENSE.chromium +27 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-arm64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-arm64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/darwin-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-x64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-x64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +5 -1
- package/runtime/include/js_bigint.h +1 -1
- package/runtime/include/js_buffer.h +4 -4
- package/runtime/include/js_builtins.h +41 -3
- package/runtime/include/js_console.h +9 -4
- package/runtime/include/js_convert.h +1 -1
- package/runtime/include/js_core.def +5 -4
- package/runtime/include/js_crypto.h +1 -1
- package/runtime/include/js_error.h +1 -1
- package/runtime/include/js_exception.h +21 -1
- package/runtime/include/js_function.h +33 -9
- package/runtime/include/js_gc.h +172 -30
- package/runtime/include/js_generator.h +2 -2
- package/runtime/include/js_host.h +19 -1
- package/runtime/include/js_jobs.h +5 -5
- package/runtime/include/js_module.h +1 -1
- package/runtime/include/js_object.h +142 -15
- package/runtime/include/js_ops.h +107 -5
- package/runtime/include/js_promise.h +3 -3
- package/runtime/include/js_regexp.h +1 -1
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +1 -1
- package/runtime/include/js_web.h +5 -1
- package/runtime/include/jscell.h +22 -15
- package/runtime/include/jscontext.h +82 -39
- package/runtime/include/jsnum.h +1 -1
- package/runtime/include/jsstring.h +19 -6
- package/runtime/include/jsvalue.h +7 -3
- package/runtime/src/arguments.c +2 -2
- package/runtime/src/array.c +4 -1
- package/runtime/src/arraybuffer.c +19 -7
- package/runtime/src/async_iter.c +4 -3
- package/runtime/src/atoms.c +38 -4
- package/runtime/src/base64.c +2 -2
- package/runtime/src/bigint.c +1 -1
- package/runtime/src/blob.c +22 -9
- package/runtime/src/boringssl_support.cc +1 -1
- package/runtime/src/buffer.c +299 -91
- package/runtime/src/builtin_table.c +1 -1
- package/runtime/src/builtins.c +30 -4
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +18 -3
- package/runtime/src/components.c +1 -1
- package/runtime/src/console.c +14 -7
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +1 -1
- package/runtime/src/crypto.c +1 -1
- package/runtime/src/crypto_asym.c +1 -1
- package/runtime/src/crypto_bn.c +1 -1
- package/runtime/src/crypto_cipher.c +10 -3
- package/runtime/src/crypto_hash.c +1 -1
- package/runtime/src/crypto_host.c +1 -1
- package/runtime/src/crypto_internal.h +1 -1
- package/runtime/src/crypto_kdf.c +1 -1
- package/runtime/src/crypto_key.c +14 -1
- package/runtime/src/crypto_pkey.c +1 -1
- package/runtime/src/crypto_subtle.c +142 -58
- package/runtime/src/crypto_tls.c +1 -1
- package/runtime/src/date.c +5 -2
- package/runtime/src/domexception.c +2 -2
- package/runtime/src/elements.c +56 -17
- package/runtime/src/elements.h +7 -2
- package/runtime/src/encoding.c +1 -1
- package/runtime/src/error.c +4 -4
- package/runtime/src/events.c +42 -14
- package/runtime/src/exception.c +1 -1
- package/runtime/src/fetch.c +241 -17
- package/runtime/src/function.c +31 -19
- package/runtime/src/gc.c +1720 -211
- package/runtime/src/gc_visit.h +87 -0
- package/runtime/src/generator.c +5 -3
- package/runtime/src/global.c +14 -6
- package/runtime/src/headers.c +10 -10
- package/runtime/src/inspect.c +76 -17
- package/runtime/src/internal.h +9 -6
- package/runtime/src/iterate.c +94 -2
- package/runtime/src/iterator.c +1 -1
- package/runtime/src/jobs.c +11 -5
- package/runtime/src/jsnum.c +2 -2
- package/runtime/src/json.c +1 -1
- package/runtime/src/math.c +9 -1
- package/runtime/src/module.c +3 -3
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +107 -74
- package/runtime/src/ops.c +21 -3
- package/runtime/src/os.c +192 -1
- package/runtime/src/os.h +33 -2
- package/runtime/src/process.c +73 -8
- package/runtime/src/promise.c +4 -4
- package/runtime/src/proxy.c +1 -1
- package/runtime/src/reflect.c +1 -1
- package/runtime/src/regexp.c +700 -11
- package/runtime/src/regexp_anchor.h +1 -1
- package/runtime/src/regexp_message.h +1 -1
- package/runtime/src/shape.c +78 -20
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +22 -8
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +64 -25
- package/runtime/src/string_builtins.c +7 -7
- package/runtime/src/symbol.c +2 -7
- package/runtime/src/test_host.c +3 -3
- package/runtime/src/tls_roots.gen.h +102 -620
- package/runtime/src/typedarray.c +8 -3
- package/runtime/src/tznames.gen.h +2 -1
- package/runtime/src/uri.c +1 -1
- package/runtime/src/url.c +42 -39
- package/runtime/src/weak.c +110 -36
- package/runtime/src/web.c +21 -3
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +7 -6
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +7 -7
- package/runtime/third_party/ada-idna/convert.mjs +89 -27
- package/runtime/third_party/ada-idna/idna.c +30 -31
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +2272 -1952
- package/runtime/third_party/boringssl/third_party/fiat/LICENSE +15 -0
- package/runtime/third_party/mozilla-ca/LICENSE +373 -0
- package/runtime/third_party/mozilla-ca/README.md +9 -0
- package/runtime/third_party/nodejs/LICENSE +47 -0
- package/runtime/third_party/nodejs/README.md +7 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +1 -1
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +2 -2
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/unicode/LICENSE +39 -0
- package/runtime/third_party/unicode/README.md +9 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE.fdlibm +10 -0
- package/runtime/third_party/v8-ieee754/README.md +3 -2
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +2 -2
package/node/prelude/stream.js
CHANGED
|
@@ -1,1345 +1,83 @@
|
|
|
1
|
-
// node:stream
|
|
2
|
-
// pipeline and
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function legacyPipe(source, dest, options) {
|
|
37
|
-
function ondata(chunk) {
|
|
38
|
-
if (dest.writable && dest.write(chunk) === false && source.pause) source.pause();
|
|
39
|
-
}
|
|
40
|
-
source.on("data", ondata);
|
|
41
|
-
function ondrain() {
|
|
42
|
-
if (source.readable && source.resume) source.resume();
|
|
43
|
-
}
|
|
44
|
-
dest.on("drain", ondrain);
|
|
45
|
-
|
|
46
|
-
let didOnEnd = false;
|
|
47
|
-
function onend() {
|
|
48
|
-
if (didOnEnd) return;
|
|
49
|
-
didOnEnd = true;
|
|
50
|
-
dest.end();
|
|
51
|
-
}
|
|
52
|
-
function onclose() {
|
|
53
|
-
if (didOnEnd) return;
|
|
54
|
-
didOnEnd = true;
|
|
55
|
-
if (typeof dest.destroy === "function") dest.destroy();
|
|
56
|
-
}
|
|
57
|
-
if (!dest._isStdio && (!options || options.end !== false)) {
|
|
58
|
-
source.on("end", onend);
|
|
59
|
-
source.on("close", onclose);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function onerror(er) {
|
|
63
|
-
cleanup();
|
|
64
|
-
if (this.listenerCount("error") === 0) this.emit("error", er);
|
|
65
|
-
}
|
|
66
|
-
source.prependListener("error", onerror);
|
|
67
|
-
dest.prependListener("error", onerror);
|
|
68
|
-
|
|
69
|
-
function cleanup() {
|
|
70
|
-
source.removeListener("data", ondata);
|
|
71
|
-
dest.removeListener("drain", ondrain);
|
|
72
|
-
source.removeListener("end", onend);
|
|
73
|
-
source.removeListener("close", onclose);
|
|
74
|
-
source.removeListener("error", onerror);
|
|
75
|
-
dest.removeListener("error", onerror);
|
|
76
|
-
source.removeListener("end", cleanup);
|
|
77
|
-
source.removeListener("close", cleanup);
|
|
78
|
-
dest.removeListener("close", cleanup);
|
|
79
|
-
}
|
|
80
|
-
source.on("end", cleanup);
|
|
81
|
-
source.on("close", cleanup);
|
|
82
|
-
dest.on("close", cleanup);
|
|
83
|
-
dest.emit("pipe", source);
|
|
84
|
-
return dest;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/* ---- Readable -------------------------------------------------------------------------------- */
|
|
88
|
-
|
|
89
|
-
class ReadableState {
|
|
90
|
-
constructor(options, stream) {
|
|
91
|
-
this.objectMode = !!(options && (options.objectMode || options.readableObjectMode));
|
|
92
|
-
const hwm = options && (options.readableHighWaterMark ?? options.highWaterMark);
|
|
93
|
-
this.highWaterMark = hwm !== undefined ? hwm : this.objectMode ? 16 : 65536;
|
|
94
|
-
this.buffer = [];
|
|
95
|
-
this.length = 0;
|
|
96
|
-
this.pipes = [];
|
|
97
|
-
this.flowing = null;
|
|
98
|
-
this.ended = false;
|
|
99
|
-
this.endEmitted = false;
|
|
100
|
-
this.reading = false;
|
|
101
|
-
this.sync = true;
|
|
102
|
-
this.needReadable = false;
|
|
103
|
-
this.emittedReadable = false;
|
|
104
|
-
this.readableListening = false;
|
|
105
|
-
this.resumeScheduled = false;
|
|
106
|
-
this.destroyed = false;
|
|
107
|
-
this.closed = false;
|
|
108
|
-
this.closeEmitted = false;
|
|
109
|
-
this.errored = null;
|
|
110
|
-
this.errorEmitted = false;
|
|
111
|
-
this.emitClose = !options || options.emitClose !== false;
|
|
112
|
-
this.autoDestroy = !options || options.autoDestroy !== false;
|
|
113
|
-
this.dataEmitted = false;
|
|
114
|
-
this.encoding = null;
|
|
115
|
-
this.decoder = null;
|
|
116
|
-
this.stream = stream;
|
|
117
|
-
if (options && options.encoding) this.setEncoding(options.encoding);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
setEncoding(enc) {
|
|
121
|
-
this.encoding = Buffer.isEncoding(enc) ? String(enc).toLowerCase().replace("-", "") : "utf8";
|
|
122
|
-
if (this.encoding === "utf-8") this.encoding = "utf8";
|
|
123
|
-
this.decoder = this.encoding === "utf8" ? new TextDecoder() : null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
decode(buf, flush) {
|
|
127
|
-
if (this.decoder) return this.decoder.decode(buf, { stream: !flush });
|
|
128
|
-
return buf.toString(this.encoding);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function Readable(options) {
|
|
133
|
-
if (!(this instanceof Readable)) return new Readable(options);
|
|
134
|
-
Stream.call(this, options);
|
|
135
|
-
this._readableState = new ReadableState(options, this);
|
|
136
|
-
if (options) {
|
|
137
|
-
if (typeof options.read === "function") this._read = options.read;
|
|
138
|
-
if (typeof options.destroy === "function") this._destroy = options.destroy;
|
|
139
|
-
if (typeof options.construct === "function") this._construct = options.construct;
|
|
140
|
-
if (options.signal) addAbortSignal(options.signal, this);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
Object.setPrototypeOf(Readable.prototype, Stream.prototype);
|
|
144
|
-
Object.setPrototypeOf(Readable, Stream);
|
|
145
|
-
|
|
146
|
-
Readable.prototype._read = function () {
|
|
147
|
-
throw codeError(Error, "The _read() method is not implemented", "ERR_METHOD_NOT_IMPLEMENTED");
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
function readableAddChunk(stream, chunk, encoding, prepend) {
|
|
151
|
-
const state = stream._readableState;
|
|
152
|
-
if (chunk === null) {
|
|
153
|
-
state.reading = false;
|
|
154
|
-
onEofChunk(stream, state);
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
if (!state.objectMode) {
|
|
158
|
-
if (typeof chunk === "string") {
|
|
159
|
-
encoding = encoding || "utf8";
|
|
160
|
-
if (state.encoding !== encoding) chunk = Buffer.from(chunk, encoding);
|
|
161
|
-
else if (state.encoding) {
|
|
162
|
-
return addChunk(stream, state, chunk, prepend);
|
|
163
|
-
}
|
|
164
|
-
} else if (isUint8(chunk) && !Buffer.isBuffer(chunk)) {
|
|
165
|
-
chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
166
|
-
} else if (!isUint8(chunk)) {
|
|
167
|
-
const e = codeError(TypeError, 'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array.', "ERR_INVALID_ARG_TYPE");
|
|
168
|
-
errorOrDestroy(stream, e);
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
if (state.decoder || (state.encoding && state.encoding !== "buffer")) chunk = state.decode(chunk, false);
|
|
172
|
-
}
|
|
173
|
-
if (state.ended && !prepend) {
|
|
174
|
-
errorOrDestroy(stream, codeError(Error, "stream.push() after EOF", "ERR_STREAM_PUSH_AFTER_EOF"));
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
if (state.destroyed || state.errored) return false;
|
|
178
|
-
state.reading = false;
|
|
179
|
-
if (!state.objectMode && chunk.length === 0) {
|
|
180
|
-
maybeReadMore(stream, state);
|
|
181
|
-
return state.length < state.highWaterMark;
|
|
182
|
-
}
|
|
183
|
-
addChunk(stream, state, chunk, prepend);
|
|
184
|
-
return !state.ended && (state.length < state.highWaterMark || state.length === 0);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function addChunk(stream, state, chunk, prepend) {
|
|
188
|
-
if (state.flowing && state.length === 0 && !state.sync && stream.listenerCount("data") > 0) {
|
|
189
|
-
state.dataEmitted = true;
|
|
190
|
-
stream.emit("data", chunk);
|
|
191
|
-
} else {
|
|
192
|
-
state.length += chunkSize(chunk, state.objectMode);
|
|
193
|
-
if (prepend) state.buffer.unshift(chunk);
|
|
194
|
-
else state.buffer.push(chunk);
|
|
195
|
-
if (state.needReadable) emitReadable(stream);
|
|
196
|
-
}
|
|
197
|
-
maybeReadMore(stream, state);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
Readable.prototype.push = function (chunk, encoding) {
|
|
201
|
-
return readableAddChunk(this, chunk, encoding, false);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
Readable.prototype.unshift = function (chunk, encoding) {
|
|
205
|
-
return readableAddChunk(this, chunk, encoding, true);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
Readable.prototype.isPaused = function () {
|
|
209
|
-
return this._readableState.flowing === false;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
Readable.prototype.setEncoding = function (enc) {
|
|
213
|
-
const state = this._readableState;
|
|
214
|
-
state.setEncoding(enc);
|
|
215
|
-
state.buffer = state.buffer.map((c) => (typeof c === "string" ? c : state.decode(c, false)));
|
|
216
|
-
return this;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
/* the chunks for read(n): n bytes (or characters), or everything */
|
|
220
|
-
function fromList(n, state) {
|
|
221
|
-
if (state.length === 0) return null;
|
|
222
|
-
let ret;
|
|
223
|
-
if (state.objectMode) ret = state.buffer.shift();
|
|
224
|
-
else if (!n || n >= state.length) {
|
|
225
|
-
ret = state.decoder || state.encoding ? state.buffer.join("") : state.buffer.length === 1 ? state.buffer[0] : Buffer.concat(state.buffer);
|
|
226
|
-
state.buffer = [];
|
|
227
|
-
} else {
|
|
228
|
-
const parts = [];
|
|
229
|
-
let need = n;
|
|
230
|
-
while (need > 0) {
|
|
231
|
-
const head = state.buffer[0];
|
|
232
|
-
if (head.length <= need) {
|
|
233
|
-
parts.push(head);
|
|
234
|
-
state.buffer.shift();
|
|
235
|
-
need -= head.length;
|
|
236
|
-
} else {
|
|
237
|
-
parts.push(head.slice(0, need));
|
|
238
|
-
state.buffer[0] = head.slice(need);
|
|
239
|
-
need = 0;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
ret = typeof parts[0] === "string" ? parts.join("") : Buffer.concat(parts);
|
|
243
|
-
}
|
|
244
|
-
state.length -= chunkSize(ret, state.objectMode);
|
|
245
|
-
return ret;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/* how much read(n) returns: one object, the first chunk when flowing, everything when n is
|
|
249
|
-
* NaN, n when buffered, else nothing until more arrives (or it ends) */
|
|
250
|
-
function howMuchToRead(n, state) {
|
|
251
|
-
if (n <= 0 || (state.length === 0 && state.ended)) return 0;
|
|
252
|
-
if (state.objectMode) return 1;
|
|
253
|
-
if (Number.isNaN(n)) return state.flowing && state.length ? state.buffer[0].length : state.length;
|
|
254
|
-
if (n <= state.length) return n;
|
|
255
|
-
return state.ended ? state.length : 0;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
Readable.prototype.read = function (n) {
|
|
259
|
-
const state = this._readableState;
|
|
260
|
-
n = n === undefined ? NaN : Number(n);
|
|
261
|
-
const nOrig = n;
|
|
262
|
-
if (n !== 0) state.emittedReadable = false;
|
|
263
|
-
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
|
264
|
-
if (state.length === 0 && state.ended) endReadable(this);
|
|
265
|
-
else emitReadable(this);
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
n = howMuchToRead(n, state);
|
|
269
|
-
if (n === 0 && state.ended) {
|
|
270
|
-
if (state.length === 0) endReadable(this);
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
let doRead = state.needReadable || state.length === 0 || state.length - n < state.highWaterMark;
|
|
274
|
-
if (state.ended || state.reading || state.destroyed || state.errored) doRead = false;
|
|
275
|
-
if (doRead) {
|
|
276
|
-
state.reading = true;
|
|
277
|
-
state.sync = true;
|
|
278
|
-
if (state.length === 0) state.needReadable = true;
|
|
279
|
-
try {
|
|
280
|
-
this._read(state.highWaterMark);
|
|
281
|
-
} catch (e) {
|
|
282
|
-
errorOrDestroy(this, e);
|
|
283
|
-
}
|
|
284
|
-
state.sync = false;
|
|
285
|
-
if (!state.reading) n = howMuchToRead(nOrig, state);
|
|
286
|
-
}
|
|
287
|
-
const ret = n > 0 ? fromList(n, state) : null;
|
|
288
|
-
if (ret === null) {
|
|
289
|
-
state.needReadable = state.length <= state.highWaterMark;
|
|
290
|
-
n = 0;
|
|
291
|
-
} else {
|
|
292
|
-
state.readableDidRead = true;
|
|
293
|
-
}
|
|
294
|
-
if (state.length === 0) {
|
|
295
|
-
if (!state.ended) state.needReadable = true;
|
|
296
|
-
if (nOrig !== n && state.ended) endReadable(this);
|
|
297
|
-
}
|
|
298
|
-
if (ret !== null && !state.errorEmitted && !state.closeEmitted) {
|
|
299
|
-
state.dataEmitted = true;
|
|
300
|
-
this.emit("data", ret);
|
|
301
|
-
}
|
|
302
|
-
return ret;
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
function onEofChunk(stream, state) {
|
|
306
|
-
if (state.ended) return;
|
|
307
|
-
if (state.decoder) {
|
|
308
|
-
const rest = state.decoder.decode();
|
|
309
|
-
if (rest.length) {
|
|
310
|
-
state.buffer.push(rest);
|
|
311
|
-
state.length += state.objectMode ? 1 : rest.length;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
state.ended = true;
|
|
315
|
-
if (state.sync) emitReadable(stream);
|
|
316
|
-
else {
|
|
317
|
-
state.needReadable = false;
|
|
318
|
-
state.emittedReadable = true;
|
|
319
|
-
emitReadable_(stream);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function emitReadable(stream) {
|
|
324
|
-
const state = stream._readableState;
|
|
325
|
-
state.needReadable = false;
|
|
326
|
-
if (!state.emittedReadable) {
|
|
327
|
-
state.emittedReadable = true;
|
|
328
|
-
nextTick(emitReadable_, stream);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
function emitReadable_(stream) {
|
|
333
|
-
const state = stream._readableState;
|
|
334
|
-
if (!state.destroyed && !state.errored && (state.length || state.ended)) {
|
|
335
|
-
stream.emit("readable");
|
|
336
|
-
state.emittedReadable = false;
|
|
337
|
-
}
|
|
338
|
-
state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
|
|
339
|
-
flow(stream);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function maybeReadMore(stream, state) {
|
|
343
|
-
if (!state.readingMore && !state.ended) {
|
|
344
|
-
state.readingMore = true;
|
|
345
|
-
nextTick(() => {
|
|
346
|
-
while (!state.reading && !state.ended && (state.length < state.highWaterMark || (state.flowing && state.length === 0))) {
|
|
347
|
-
const len = state.length;
|
|
348
|
-
stream.read(0);
|
|
349
|
-
if (len === state.length) break;
|
|
350
|
-
}
|
|
351
|
-
state.readingMore = false;
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
Readable.prototype.on = function (ev, fn) {
|
|
357
|
-
const res = Stream.prototype.on.call(this, ev, fn);
|
|
358
|
-
const state = this._readableState;
|
|
359
|
-
if (ev === "data") {
|
|
360
|
-
state.readableListening = this.listenerCount("readable") > 0;
|
|
361
|
-
if (state.flowing !== false) this.resume();
|
|
362
|
-
} else if (ev === "readable") {
|
|
363
|
-
if (!state.endEmitted && !state.readableListening) {
|
|
364
|
-
state.readableListening = state.needReadable = true;
|
|
365
|
-
state.flowing = false;
|
|
366
|
-
state.emittedReadable = false;
|
|
367
|
-
if (state.length) emitReadable(this);
|
|
368
|
-
else if (!state.reading) nextTick(() => this.read(0));
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return res;
|
|
372
|
-
};
|
|
373
|
-
Readable.prototype.addListener = Readable.prototype.on;
|
|
374
|
-
|
|
375
|
-
Readable.prototype.removeListener = function (ev, fn) {
|
|
376
|
-
const res = Stream.prototype.removeListener.call(this, ev, fn);
|
|
377
|
-
if (ev === "readable") nextTick(updateReadableListening, this);
|
|
378
|
-
return res;
|
|
379
|
-
};
|
|
380
|
-
Readable.prototype.off = Readable.prototype.removeListener;
|
|
381
|
-
|
|
382
|
-
function updateReadableListening(self) {
|
|
383
|
-
const state = self._readableState;
|
|
384
|
-
state.readableListening = self.listenerCount("readable") > 0;
|
|
385
|
-
if (state.resumeScheduled && state.paused === false) state.flowing = true;
|
|
386
|
-
else if (self.listenerCount("data") > 0) self.resume();
|
|
387
|
-
else if (!state.readableListening) state.flowing = null;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
Readable.prototype.resume = function () {
|
|
391
|
-
const state = this._readableState;
|
|
392
|
-
if (!state.flowing) {
|
|
393
|
-
state.flowing = !state.readableListening;
|
|
394
|
-
if (!state.resumeScheduled) {
|
|
395
|
-
state.resumeScheduled = true;
|
|
396
|
-
nextTick(() => {
|
|
397
|
-
if (!state.reading) this.read(0);
|
|
398
|
-
state.resumeScheduled = false;
|
|
399
|
-
this.emit("resume");
|
|
400
|
-
flow(this);
|
|
401
|
-
if (state.flowing && !state.reading) this.read(0);
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
state.paused = false;
|
|
406
|
-
return this;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
Readable.prototype.pause = function () {
|
|
410
|
-
const state = this._readableState;
|
|
411
|
-
if (state.flowing !== false) {
|
|
412
|
-
state.flowing = false;
|
|
413
|
-
this.emit("pause");
|
|
414
|
-
}
|
|
415
|
-
state.paused = true;
|
|
416
|
-
return this;
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
function flow(stream) {
|
|
420
|
-
const state = stream._readableState;
|
|
421
|
-
while (state.flowing && stream.read() !== null);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function endReadable(stream) {
|
|
425
|
-
const state = stream._readableState;
|
|
426
|
-
if (!state.endEmitted) {
|
|
427
|
-
state.ended = true;
|
|
428
|
-
nextTick(() => {
|
|
429
|
-
if (!state.errored && !state.closeEmitted && !state.endEmitted && state.length === 0) {
|
|
430
|
-
state.endEmitted = true;
|
|
431
|
-
stream.emit("end");
|
|
432
|
-
const ws = stream._writableState;
|
|
433
|
-
if (stream.writable && stream.allowHalfOpen === false) { /* a Duplex that isn't half-open ends its writable side too */
|
|
434
|
-
nextTick(() => {
|
|
435
|
-
if (stream.writable && !stream.writableEnded && !stream.destroyed) stream.end();
|
|
436
|
-
});
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
const autoDestroy = !ws || (ws.autoDestroy && (ws.finished || ws.writable === false));
|
|
440
|
-
if (state.autoDestroy && autoDestroy) stream.destroy();
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
447
|
-
const state = this._readableState;
|
|
448
|
-
state.pipes.push(dest);
|
|
449
|
-
const doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
|
450
|
-
const onend = () => dest.end();
|
|
451
|
-
if (doEnd) this.once("end", onend);
|
|
452
|
-
let ondrain;
|
|
453
|
-
const ondata = (chunk) => {
|
|
454
|
-
const ret = dest.write(chunk);
|
|
455
|
-
if (ret === false) {
|
|
456
|
-
this.pause();
|
|
457
|
-
if (!ondrain) {
|
|
458
|
-
ondrain = () => {
|
|
459
|
-
ondrain = null;
|
|
460
|
-
this.resume();
|
|
461
|
-
};
|
|
462
|
-
dest.once("drain", ondrain);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
this.on("data", ondata);
|
|
467
|
-
const cleanup = () => {
|
|
468
|
-
this.removeListener("data", ondata);
|
|
469
|
-
this.removeListener("end", onend);
|
|
470
|
-
dest.removeListener("close", onclose);
|
|
471
|
-
dest.removeListener("finish", onfinish);
|
|
472
|
-
dest.removeListener("error", onerror);
|
|
473
|
-
};
|
|
474
|
-
const onerror = (er) => {
|
|
475
|
-
this.unpipe(dest);
|
|
476
|
-
dest.removeListener("error", onerror);
|
|
477
|
-
if (dest.listenerCount("error") === 0) {
|
|
478
|
-
const s = dest._writableState || dest._readableState;
|
|
479
|
-
if (s && !s.errorEmitted) errorOrDestroy(dest, er);
|
|
480
|
-
else dest.emit("error", er);
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
dest.prependListener("error", onerror);
|
|
484
|
-
const onclose = () => {
|
|
485
|
-
dest.removeListener("finish", onfinish);
|
|
486
|
-
this.unpipe(dest);
|
|
487
|
-
};
|
|
488
|
-
const onfinish = () => {
|
|
489
|
-
dest.removeListener("close", onclose);
|
|
490
|
-
this.unpipe(dest);
|
|
491
|
-
};
|
|
492
|
-
dest.once("close", onclose);
|
|
493
|
-
dest.once("finish", onfinish);
|
|
494
|
-
dest._pipeCleanup = cleanup;
|
|
495
|
-
dest.emit("pipe", this);
|
|
496
|
-
if (dest.writableNeedDrain === true) this.pause();
|
|
497
|
-
else if (!state.flowing) this.resume();
|
|
498
|
-
return dest;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
Readable.prototype.unpipe = function (dest) {
|
|
502
|
-
const state = this._readableState;
|
|
503
|
-
const dests = dest ? [dest] : state.pipes.slice();
|
|
504
|
-
for (const d of dests) {
|
|
505
|
-
const i = state.pipes.indexOf(d);
|
|
506
|
-
if (i < 0) continue;
|
|
507
|
-
state.pipes.splice(i, 1);
|
|
508
|
-
if (d._pipeCleanup) d._pipeCleanup();
|
|
509
|
-
d.emit("unpipe", this);
|
|
510
|
-
}
|
|
511
|
-
if (state.pipes.length === 0) this.pause();
|
|
512
|
-
return this;
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
Readable.prototype[Symbol.asyncIterator] = function () {
|
|
516
|
-
return createAsyncIterator(this);
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
Readable.prototype.iterator = function (options) {
|
|
520
|
-
return createAsyncIterator(this, options);
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
async function* createAsyncIterator(stream, options) {
|
|
524
|
-
let wake = () => {};
|
|
525
|
-
const next = () => wake();
|
|
526
|
-
stream.on("readable", next);
|
|
527
|
-
let error;
|
|
528
|
-
let done = false;
|
|
529
|
-
finished(stream, { writable: false }, (err) => {
|
|
530
|
-
error = err ? aggregateTwoErrors(error, err) : null;
|
|
531
|
-
done = true;
|
|
532
|
-
wake();
|
|
533
|
-
});
|
|
534
|
-
try {
|
|
535
|
-
for (;;) {
|
|
536
|
-
const chunk = stream.destroyed ? null : stream.read();
|
|
537
|
-
if (chunk !== null) yield chunk;
|
|
538
|
-
else if (error) throw error;
|
|
539
|
-
else if (error === null || done) return;
|
|
540
|
-
else await new Promise((resolve) => (wake = resolve));
|
|
541
|
-
}
|
|
542
|
-
} catch (err) {
|
|
543
|
-
error = aggregateTwoErrors(error, err);
|
|
544
|
-
throw error;
|
|
545
|
-
} finally {
|
|
546
|
-
if ((error || options?.destroyOnReturn !== false) && (error === undefined || stream._readableState.autoDestroy)) destroyImpl(stream, null);
|
|
547
|
-
else stream.off?.("readable", next);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
function aggregateTwoErrors(inner, outer) {
|
|
552
|
-
return inner || outer;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const readableGetters = {
|
|
556
|
-
readable: (s, st) => !!(st.readable !== false && !st.destroyed && !st.errorEmitted && !st.endEmitted),
|
|
557
|
-
readableDidRead: (s, st) => !!st.readableDidRead,
|
|
558
|
-
readableAborted: (s, st) => !!(st.readable !== false && (st.destroyed || st.errored) && !st.endEmitted),
|
|
559
|
-
readableHighWaterMark: (s, st) => st.highWaterMark,
|
|
560
|
-
readableBuffer: (s, st) => st.buffer,
|
|
561
|
-
readableFlowing: (s, st) => st.flowing,
|
|
562
|
-
readableLength: (s, st) => st.length,
|
|
563
|
-
readableObjectMode: (s, st) => st.objectMode,
|
|
564
|
-
readableEncoding: (s, st) => st.encoding,
|
|
565
|
-
readableEnded: (s, st) => st.endEmitted,
|
|
566
|
-
errored: (s, st) => st.errored,
|
|
567
|
-
closed: (s, st) => st.closed,
|
|
568
|
-
destroyed: (s, st) => st.destroyed,
|
|
569
|
-
};
|
|
570
|
-
for (const name of Object.keys(readableGetters)) {
|
|
571
|
-
const get = readableGetters[name];
|
|
572
|
-
Object.defineProperty(Readable.prototype, name, {
|
|
573
|
-
get() {
|
|
574
|
-
const st = this._readableState;
|
|
575
|
-
return st ? get(this, st) : undefined;
|
|
576
|
-
},
|
|
577
|
-
set(v) {
|
|
578
|
-
if (name === "readable" && this._readableState) this._readableState.readable = v;
|
|
579
|
-
else if (name === "destroyed" && this._readableState) this._readableState.destroyed = v;
|
|
580
|
-
else if (name === "readableFlowing" && this._readableState) this._readableState.flowing = v;
|
|
581
|
-
},
|
|
582
|
-
enumerable: false,
|
|
583
|
-
configurable: true,
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
Readable.from = function (iterable, opts) {
|
|
588
|
-
if (typeof iterable === "string" || isUint8(iterable)) {
|
|
589
|
-
return new Readable({
|
|
590
|
-
objectMode: true,
|
|
591
|
-
...opts,
|
|
592
|
-
read() {
|
|
593
|
-
this.push(iterable);
|
|
594
|
-
this.push(null);
|
|
595
|
-
},
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
const iterator = iterable[Symbol.asyncIterator] ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
|
599
|
-
let reading = false;
|
|
600
|
-
const readable = new Readable({
|
|
601
|
-
objectMode: true,
|
|
602
|
-
highWaterMark: 1,
|
|
603
|
-
...opts,
|
|
604
|
-
async read() {
|
|
605
|
-
if (reading) return;
|
|
606
|
-
reading = true;
|
|
607
|
-
try {
|
|
608
|
-
for (;;) {
|
|
609
|
-
const { value, done } = await iterator.next();
|
|
610
|
-
if (done) {
|
|
611
|
-
this.push(null);
|
|
612
|
-
break;
|
|
613
|
-
}
|
|
614
|
-
const chunk = value && typeof value.then === "function" ? await value : value;
|
|
615
|
-
if (chunk === null) throw codeError(TypeError, "May not write null values to stream", "ERR_STREAM_NULL_VALUES");
|
|
616
|
-
if (!this.push(chunk)) break;
|
|
617
|
-
}
|
|
618
|
-
} catch (err) {
|
|
619
|
-
this.destroy(err);
|
|
620
|
-
}
|
|
621
|
-
reading = false;
|
|
622
|
-
},
|
|
623
|
-
destroy(error, cb) {
|
|
624
|
-
Promise.resolve(typeof iterator.return === "function" ? iterator.return() : undefined).then(() => cb(error), (e) => cb(e || error));
|
|
625
|
-
},
|
|
626
|
-
});
|
|
627
|
-
return readable;
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
/* Readable.toWeb(readable): a ReadableStream of its chunks (as Uint8Arrays) */
|
|
631
|
-
Readable.toWeb = function (streamReadable) {
|
|
632
|
-
const objectMode = streamReadable.readableObjectMode;
|
|
633
|
-
let controller;
|
|
634
|
-
let closed = false;
|
|
635
|
-
const onData = (chunk) => {
|
|
636
|
-
if (closed) return;
|
|
637
|
-
if (Buffer.isBuffer(chunk) && !objectMode) chunk = new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
638
|
-
controller.enqueue(chunk);
|
|
639
|
-
if (controller.desiredSize <= 0) streamReadable.pause();
|
|
640
|
-
};
|
|
641
|
-
return new ReadableStream({
|
|
642
|
-
start(c) {
|
|
643
|
-
controller = c;
|
|
644
|
-
streamReadable.on("data", onData);
|
|
645
|
-
finished(streamReadable, (error) => {
|
|
646
|
-
if (closed) return;
|
|
647
|
-
closed = true;
|
|
648
|
-
if (error && error.code !== "ERR_STREAM_PREMATURE_CLOSE") controller.error(error);
|
|
649
|
-
else if (error) controller.error(error);
|
|
650
|
-
else controller.close();
|
|
651
|
-
});
|
|
652
|
-
if (streamReadable.readableEnded) {
|
|
653
|
-
closed = true;
|
|
654
|
-
controller.close();
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
pull() {
|
|
658
|
-
streamReadable.resume();
|
|
659
|
-
},
|
|
660
|
-
cancel(reason) {
|
|
661
|
-
closed = true;
|
|
662
|
-
destroyImpl(streamReadable, reason);
|
|
663
|
-
},
|
|
664
|
-
}, { highWaterMark: objectMode ? 16 : 65536, size: objectMode ? undefined : (chunk) => chunk.byteLength });
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
/* Readable.fromWeb(readableStream): a Readable of its chunks */
|
|
668
|
-
Readable.fromWeb = function (readableStream, options) {
|
|
669
|
-
const reader = readableStream.getReader();
|
|
670
|
-
let closed = false;
|
|
671
|
-
const readable = new Readable({
|
|
672
|
-
objectMode: !!(options && options.objectMode),
|
|
673
|
-
highWaterMark: options?.highWaterMark,
|
|
674
|
-
encoding: options?.encoding,
|
|
675
|
-
read() {
|
|
676
|
-
reader.read().then(({ value, done }) => {
|
|
677
|
-
if (done) this.push(null);
|
|
678
|
-
else this.push(value);
|
|
679
|
-
}, (error) => this.destroy(error));
|
|
680
|
-
},
|
|
681
|
-
destroy(error, callback) {
|
|
682
|
-
if (!closed) reader.cancel(error).then(() => callback(error), (e) => callback(e));
|
|
683
|
-
else callback(error);
|
|
684
|
-
},
|
|
685
|
-
});
|
|
686
|
-
reader.closed.then(() => (closed = true), () => (closed = true));
|
|
687
|
-
return readable;
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
/* ---- Writable -------------------------------------------------------------------------------- */
|
|
691
|
-
|
|
692
|
-
class WritableState {
|
|
693
|
-
constructor(options, stream) {
|
|
694
|
-
this.objectMode = !!(options && (options.objectMode || options.writableObjectMode));
|
|
695
|
-
const hwm = options && (options.writableHighWaterMark ?? options.highWaterMark);
|
|
696
|
-
this.highWaterMark = hwm !== undefined ? hwm : this.objectMode ? 16 : 65536;
|
|
697
|
-
this.decodeStrings = !options || options.decodeStrings !== false;
|
|
698
|
-
this.defaultEncoding = (options && options.defaultEncoding) || "utf8";
|
|
699
|
-
this.length = 0;
|
|
700
|
-
this.writing = false;
|
|
701
|
-
this.corked = 0;
|
|
702
|
-
this.buffered = [];
|
|
703
|
-
this.needDrain = false;
|
|
704
|
-
this.ending = false;
|
|
705
|
-
this.ended = false;
|
|
706
|
-
this.finished = false;
|
|
707
|
-
this.finalCalled = false;
|
|
708
|
-
this.prefinished = false;
|
|
709
|
-
this.destroyed = false;
|
|
710
|
-
this.closed = false;
|
|
711
|
-
this.closeEmitted = false;
|
|
712
|
-
this.errored = null;
|
|
713
|
-
this.errorEmitted = false;
|
|
714
|
-
this.emitClose = !options || options.emitClose !== false;
|
|
715
|
-
this.autoDestroy = !options || options.autoDestroy !== false;
|
|
716
|
-
this.pendingcb = 0;
|
|
717
|
-
this.stream = stream;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
export function Writable(options) {
|
|
722
|
-
/* as Node checks: Duplex first, and without Writable's Symbol.hasInstance (which reads
|
|
723
|
-
* _writableState: a lazy stream, crypto's Hash, would make it while it is being made) */
|
|
724
|
-
if (!(this instanceof Duplex) && !Function.prototype[Symbol.hasInstance].call(Writable, this)) return new Writable(options);
|
|
725
|
-
Stream.call(this, options);
|
|
726
|
-
this._writableState = new WritableState(options, this);
|
|
727
|
-
if (options) {
|
|
728
|
-
if (typeof options.write === "function") this._write = options.write;
|
|
729
|
-
if (typeof options.writev === "function") this._writev = options.writev;
|
|
730
|
-
if (typeof options.destroy === "function") this._destroy = options.destroy;
|
|
731
|
-
if (typeof options.final === "function") this._final = options.final;
|
|
732
|
-
if (options.signal) addAbortSignal(options.signal, this);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
Object.setPrototypeOf(Writable.prototype, Stream.prototype);
|
|
736
|
-
Object.setPrototypeOf(Writable, Stream);
|
|
737
|
-
|
|
738
|
-
Object.defineProperty(Writable, Symbol.hasInstance, {
|
|
739
|
-
value(object) {
|
|
740
|
-
if (Function.prototype[Symbol.hasInstance].call(this, object)) return true;
|
|
741
|
-
if (this !== Writable) return false;
|
|
742
|
-
return !!(object && object._writableState);
|
|
743
|
-
},
|
|
744
|
-
configurable: true,
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
Writable.prototype._write = function (chunk, encoding, cb) {
|
|
748
|
-
if (this._writev) this._writev([{ chunk, encoding }], cb);
|
|
749
|
-
else throw codeError(Error, "The _write() method is not implemented", "ERR_METHOD_NOT_IMPLEMENTED");
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
Writable.prototype.write = function (chunk, encoding, cb) {
|
|
753
|
-
const state = this._writableState;
|
|
754
|
-
if (typeof encoding === "function") {
|
|
755
|
-
cb = encoding;
|
|
756
|
-
encoding = null;
|
|
757
|
-
}
|
|
758
|
-
if (!encoding) encoding = state.defaultEncoding;
|
|
759
|
-
if (typeof cb !== "function") cb = () => {};
|
|
760
|
-
if (chunk === null) throw codeError(TypeError, "May not write null values to stream", "ERR_STREAM_NULL_VALUES");
|
|
761
|
-
if (!state.objectMode) {
|
|
762
|
-
if (typeof chunk === "string") {
|
|
763
|
-
if (state.decodeStrings !== false) {
|
|
764
|
-
chunk = Buffer.from(chunk, encoding);
|
|
765
|
-
encoding = "buffer";
|
|
766
|
-
}
|
|
767
|
-
} else if (isUint8(chunk)) {
|
|
768
|
-
if (!Buffer.isBuffer(chunk)) chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
769
|
-
encoding = "buffer";
|
|
770
|
-
} else {
|
|
771
|
-
throw codeError(TypeError, 'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array.', "ERR_INVALID_ARG_TYPE");
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
let err;
|
|
775
|
-
if (state.ending) err = codeError(Error, "write after end", "ERR_STREAM_WRITE_AFTER_END");
|
|
776
|
-
else if (state.destroyed) err = codeError(Error, "Cannot call write after a stream was destroyed", "ERR_STREAM_DESTROYED");
|
|
777
|
-
if (err) {
|
|
778
|
-
nextTick(cb, err);
|
|
779
|
-
errorOrDestroy(this, err, true);
|
|
780
|
-
return err;
|
|
781
|
-
}
|
|
782
|
-
state.pendingcb++;
|
|
783
|
-
const len = state.objectMode ? 1 : chunk.length;
|
|
784
|
-
state.length += len;
|
|
785
|
-
const ret = state.length < state.highWaterMark;
|
|
786
|
-
if (!ret) state.needDrain = true;
|
|
787
|
-
if (state.writing || state.corked || state.errored) state.buffered.push({ chunk, encoding, callback: cb });
|
|
788
|
-
else doWrite(this, state, len, chunk, encoding, cb);
|
|
789
|
-
return ret && !state.errored && !state.destroyed;
|
|
790
|
-
};
|
|
791
|
-
|
|
792
|
-
function doWrite(stream, state, len, chunk, encoding, cb) {
|
|
793
|
-
state.writelen = len;
|
|
794
|
-
state.writecb = cb;
|
|
795
|
-
state.writing = true;
|
|
796
|
-
state.sync = true;
|
|
797
|
-
if (state.destroyed) onwrite(stream, codeError(Error, "Cannot call write after a stream was destroyed", "ERR_STREAM_DESTROYED"));
|
|
798
|
-
else stream._write(chunk, encoding, (er) => onwrite(stream, er));
|
|
799
|
-
state.sync = false;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
function onwrite(stream, er) {
|
|
803
|
-
const state = stream._writableState;
|
|
804
|
-
const cb = state.writecb;
|
|
805
|
-
if (typeof cb !== "function") {
|
|
806
|
-
errorOrDestroy(stream, codeError(Error, "Callback called multiple times", "ERR_MULTIPLE_CALLBACK"));
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
state.writing = false;
|
|
810
|
-
state.writecb = null;
|
|
811
|
-
state.length -= state.writelen;
|
|
812
|
-
state.writelen = 0;
|
|
813
|
-
if (er) {
|
|
814
|
-
if (!state.errored) state.errored = er;
|
|
815
|
-
if (state.sync) nextTick(onwriteError, stream, state, er, cb);
|
|
816
|
-
else onwriteError(stream, state, er, cb);
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
if (state.buffered.length > 0) clearBuffer(stream, state);
|
|
820
|
-
if (state.sync) nextTick(afterWrite, stream, state, cb);
|
|
821
|
-
else afterWrite(stream, state, cb);
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
function onwriteError(stream, state, er, cb) {
|
|
825
|
-
--state.pendingcb;
|
|
826
|
-
cb(er);
|
|
827
|
-
errorBuffer(state);
|
|
828
|
-
errorOrDestroy(stream, er);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
function afterWrite(stream, state, cb) {
|
|
832
|
-
const needDrain = !state.ending && !stream.destroyed && state.length === 0 && state.needDrain;
|
|
833
|
-
if (needDrain) {
|
|
834
|
-
state.needDrain = false;
|
|
835
|
-
stream.emit("drain");
|
|
836
|
-
}
|
|
837
|
-
state.pendingcb--;
|
|
838
|
-
cb(null);
|
|
839
|
-
if (state.destroyed) errorBuffer(state);
|
|
840
|
-
finishMaybe(stream, state);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
function errorBuffer(state) {
|
|
844
|
-
if (state.writing) return;
|
|
845
|
-
for (const { chunk, callback } of state.buffered) {
|
|
846
|
-
state.length -= state.objectMode ? 1 : chunk.length;
|
|
847
|
-
state.pendingcb--;
|
|
848
|
-
callback(state.errored ?? codeError(Error, "Cannot call write after a stream was destroyed", "ERR_STREAM_DESTROYED"));
|
|
849
|
-
}
|
|
850
|
-
state.buffered = [];
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
function clearBuffer(stream, state) {
|
|
854
|
-
if (state.corked || state.destroyed || state.writing || state.buffered.length === 0) return;
|
|
855
|
-
const { chunk, encoding, callback } = state.buffered.shift();
|
|
856
|
-
doWrite(stream, state, state.objectMode ? 1 : chunk.length, chunk, encoding, callback);
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
Writable.prototype.cork = function () {
|
|
860
|
-
this._writableState.corked++;
|
|
861
|
-
};
|
|
862
|
-
|
|
863
|
-
Writable.prototype.uncork = function () {
|
|
864
|
-
const state = this._writableState;
|
|
865
|
-
if (state.corked) {
|
|
866
|
-
state.corked--;
|
|
867
|
-
if (!state.writing) clearBuffer(this, state);
|
|
868
|
-
}
|
|
869
|
-
};
|
|
870
|
-
|
|
871
|
-
Writable.prototype.setDefaultEncoding = function (encoding) {
|
|
872
|
-
this._writableState.defaultEncoding = encoding;
|
|
873
|
-
return this;
|
|
874
|
-
};
|
|
875
|
-
|
|
876
|
-
Writable.prototype.end = function (chunk, encoding, cb) {
|
|
877
|
-
const state = this._writableState;
|
|
878
|
-
if (typeof chunk === "function") {
|
|
879
|
-
cb = chunk;
|
|
880
|
-
chunk = null;
|
|
881
|
-
encoding = null;
|
|
882
|
-
} else if (typeof encoding === "function") {
|
|
883
|
-
cb = encoding;
|
|
884
|
-
encoding = null;
|
|
885
|
-
}
|
|
886
|
-
let err;
|
|
887
|
-
if (chunk !== null && chunk !== undefined) {
|
|
888
|
-
const ret = this.write(chunk, encoding);
|
|
889
|
-
if (ret instanceof Error) err = ret;
|
|
890
|
-
}
|
|
891
|
-
if (state.corked) {
|
|
892
|
-
state.corked = 1;
|
|
893
|
-
this.uncork();
|
|
894
|
-
}
|
|
895
|
-
if (err) {
|
|
896
|
-
/* already reported */
|
|
897
|
-
} else if (!state.errored && !state.ending) {
|
|
898
|
-
state.ending = true;
|
|
899
|
-
finishMaybe(this, state, true);
|
|
900
|
-
state.ended = true;
|
|
901
|
-
} else if (state.finished) {
|
|
902
|
-
err = codeError(Error, "Cannot call end after a stream was finished", "ERR_STREAM_ALREADY_FINISHED");
|
|
903
|
-
} else if (state.destroyed) {
|
|
904
|
-
err = codeError(Error, "Cannot call end after a stream was destroyed", "ERR_STREAM_DESTROYED");
|
|
905
|
-
}
|
|
906
|
-
if (typeof cb === "function") {
|
|
907
|
-
if (err || state.finished) nextTick(cb, err);
|
|
908
|
-
else (state.finishCallbacks ||= []).push(cb);
|
|
909
|
-
}
|
|
910
|
-
return this;
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
function needFinish(state) {
|
|
914
|
-
return state.ending && !state.destroyed && state.length === 0 && !state.errored && state.buffered.length === 0 &&
|
|
915
|
-
!state.finished && !state.writing && !state.errorEmitted && !state.closeEmitted;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
function prefinish(stream, state) {
|
|
919
|
-
if (!state.prefinished && !state.finalCalled) {
|
|
920
|
-
if (typeof stream._final === "function" && !state.destroyed) {
|
|
921
|
-
state.finalCalled = true;
|
|
922
|
-
state.sync = true;
|
|
923
|
-
state.pendingcb++;
|
|
924
|
-
let called = false;
|
|
925
|
-
const onFinal = (err) => {
|
|
926
|
-
if (called) return;
|
|
927
|
-
called = true;
|
|
928
|
-
state.pendingcb--;
|
|
929
|
-
if (err) {
|
|
930
|
-
for (const cb of state.finishCallbacks || []) cb(err);
|
|
931
|
-
state.finishCallbacks = [];
|
|
932
|
-
errorOrDestroy(stream, err, state.sync);
|
|
933
|
-
} else if (needFinish(state)) {
|
|
934
|
-
state.prefinished = true;
|
|
935
|
-
stream.emit("prefinish");
|
|
936
|
-
state.pendingcb++;
|
|
937
|
-
nextTick(finish, stream, state);
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
try {
|
|
941
|
-
stream._final(onFinal);
|
|
942
|
-
} catch (err) {
|
|
943
|
-
onFinal(err);
|
|
944
|
-
}
|
|
945
|
-
state.sync = false;
|
|
946
|
-
} else {
|
|
947
|
-
state.prefinished = true;
|
|
948
|
-
stream.emit("prefinish");
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
function finishMaybe(stream, state, sync) {
|
|
954
|
-
if (needFinish(state)) {
|
|
955
|
-
prefinish(stream, state);
|
|
956
|
-
if (state.pendingcb === 0) {
|
|
957
|
-
if (sync) {
|
|
958
|
-
state.pendingcb++;
|
|
959
|
-
nextTick(() => {
|
|
960
|
-
if (needFinish(state)) finish(stream, state);
|
|
961
|
-
else state.pendingcb--;
|
|
962
|
-
});
|
|
963
|
-
} else if (needFinish(state)) {
|
|
964
|
-
state.pendingcb++;
|
|
965
|
-
finish(stream, state);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
function finish(stream, state) {
|
|
972
|
-
state.pendingcb--;
|
|
973
|
-
state.finished = true;
|
|
974
|
-
for (const cb of state.finishCallbacks || []) cb(null);
|
|
975
|
-
state.finishCallbacks = [];
|
|
976
|
-
stream.emit("finish");
|
|
977
|
-
if (state.autoDestroy) {
|
|
978
|
-
const rState = stream._readableState;
|
|
979
|
-
const autoDestroy = !rState || (rState.autoDestroy && (rState.endEmitted || rState.readable === false));
|
|
980
|
-
if (autoDestroy) stream.destroy();
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
const writableGetters = {
|
|
985
|
-
writable: (s, st) => !!(st.writable !== false && !st.destroyed && !st.errored && !st.ending && !st.ended),
|
|
986
|
-
writableFinished: (s, st) => st.finished,
|
|
987
|
-
writableObjectMode: (s, st) => st.objectMode,
|
|
988
|
-
writableBuffer: (s, st) => st.buffered.map((b) => b.chunk),
|
|
989
|
-
writableEnded: (s, st) => st.ending,
|
|
990
|
-
writableNeedDrain: (s, st) => !st.destroyed && !st.ending && st.needDrain,
|
|
991
|
-
writableHighWaterMark: (s, st) => st.highWaterMark,
|
|
992
|
-
writableCorked: (s, st) => st.corked,
|
|
993
|
-
writableLength: (s, st) => st.length,
|
|
994
|
-
writableAborted: (s, st) => !!(st.writable !== false && (st.destroyed || st.errored) && !st.finished),
|
|
995
|
-
};
|
|
996
|
-
for (const name of Object.keys(writableGetters)) {
|
|
997
|
-
const get = writableGetters[name];
|
|
998
|
-
Object.defineProperty(Writable.prototype, name, {
|
|
999
|
-
get() {
|
|
1000
|
-
const st = this._writableState;
|
|
1001
|
-
return st ? get(this, st) : undefined;
|
|
1002
|
-
},
|
|
1003
|
-
set(v) {
|
|
1004
|
-
if (name === "writable" && this._writableState) this._writableState.writable = v;
|
|
1005
|
-
},
|
|
1006
|
-
enumerable: false,
|
|
1007
|
-
configurable: true,
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
for (const name of ["destroyed", "errored", "closed"]) {
|
|
1011
|
-
Object.defineProperty(Writable.prototype, name, {
|
|
1012
|
-
get() {
|
|
1013
|
-
const st = this._writableState;
|
|
1014
|
-
return st ? (name === "destroyed" ? st.destroyed : name === "errored" ? st.errored : st.closed) : undefined;
|
|
1015
|
-
},
|
|
1016
|
-
set(v) {
|
|
1017
|
-
if (name === "destroyed" && this._writableState) this._writableState.destroyed = v;
|
|
1018
|
-
},
|
|
1019
|
-
enumerable: false,
|
|
1020
|
-
configurable: true,
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
Writable.fromWeb = function (writableStream) {
|
|
1025
|
-
const writer = writableStream.getWriter();
|
|
1026
|
-
return new Writable({
|
|
1027
|
-
write(chunk, encoding, cb) {
|
|
1028
|
-
writer.write(chunk).then(() => cb(), cb);
|
|
1029
|
-
},
|
|
1030
|
-
final(cb) {
|
|
1031
|
-
writer.close().then(() => cb(), cb);
|
|
1032
|
-
},
|
|
1033
|
-
});
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
/* ---- destroy --------------------------------------------------------------------------------- */
|
|
1037
|
-
|
|
1038
|
-
function destroyImpl(stream, err, cb) {
|
|
1039
|
-
const r = stream._readableState;
|
|
1040
|
-
const w = stream._writableState;
|
|
1041
|
-
const s = w || r;
|
|
1042
|
-
if ((w && w.destroyed) || (r && r.destroyed)) {
|
|
1043
|
-
if (typeof cb === "function") cb();
|
|
1044
|
-
return stream;
|
|
1045
|
-
}
|
|
1046
|
-
if (err) {
|
|
1047
|
-
if (w && !w.errored) w.errored = err;
|
|
1048
|
-
if (r && !r.errored) r.errored = err;
|
|
1049
|
-
}
|
|
1050
|
-
if (w) w.destroyed = true;
|
|
1051
|
-
if (r) r.destroyed = true;
|
|
1052
|
-
const onDestroy = (er) => {
|
|
1053
|
-
if (er) {
|
|
1054
|
-
if (w && !w.errored) w.errored = er;
|
|
1055
|
-
if (r && !r.errored) r.errored = er;
|
|
1056
|
-
}
|
|
1057
|
-
if (w) w.closed = true;
|
|
1058
|
-
if (r) r.closed = true;
|
|
1059
|
-
if (typeof cb === "function") cb(er);
|
|
1060
|
-
nextTick(() => {
|
|
1061
|
-
if (er) emitErrorNT(stream, er);
|
|
1062
|
-
if ((w && w.emitClose === false) || (r && r.emitClose === false)) return;
|
|
1063
|
-
if (w) w.closeEmitted = true;
|
|
1064
|
-
if (r) r.closeEmitted = true;
|
|
1065
|
-
stream.emit("close");
|
|
1066
|
-
});
|
|
1067
|
-
};
|
|
1068
|
-
try {
|
|
1069
|
-
stream._destroy(err || null, onDestroy);
|
|
1070
|
-
} catch (e) {
|
|
1071
|
-
onDestroy(e);
|
|
1072
|
-
}
|
|
1073
|
-
void s;
|
|
1074
|
-
return stream;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
function emitErrorNT(stream, err) {
|
|
1078
|
-
const r = stream._readableState;
|
|
1079
|
-
const w = stream._writableState;
|
|
1080
|
-
if ((w && w.errorEmitted) || (r && r.errorEmitted)) return;
|
|
1081
|
-
if (w) w.errorEmitted = true;
|
|
1082
|
-
if (r) r.errorEmitted = true;
|
|
1083
|
-
stream.emit("error", err);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
function errorOrDestroy(stream, err, sync) {
|
|
1087
|
-
const r = stream._readableState;
|
|
1088
|
-
const w = stream._writableState;
|
|
1089
|
-
if ((w && w.destroyed) || (r && r.destroyed)) return;
|
|
1090
|
-
if ((r && r.autoDestroy) || (w && w.autoDestroy)) stream.destroy(err);
|
|
1091
|
-
else if (err) {
|
|
1092
|
-
if (w && !w.errored) w.errored = err;
|
|
1093
|
-
if (r && !r.errored) r.errored = err;
|
|
1094
|
-
if (sync) nextTick(emitErrorNT, stream, err);
|
|
1095
|
-
else emitErrorNT(stream, err);
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
Readable.prototype.destroy = function (err, cb) {
|
|
1100
|
-
return destroyImpl(this, err, cb);
|
|
1101
|
-
};
|
|
1102
|
-
Readable.prototype._destroy = function (err, cb) {
|
|
1103
|
-
cb(err);
|
|
1104
|
-
};
|
|
1105
|
-
Writable.prototype.destroy = Readable.prototype.destroy;
|
|
1106
|
-
Writable.prototype._destroy = Readable.prototype._destroy;
|
|
1107
|
-
|
|
1108
|
-
/* ---- Duplex, Transform, PassThrough ---------------------------------------------------------- */
|
|
1109
|
-
|
|
1110
|
-
export function Duplex(options) {
|
|
1111
|
-
if (!(this instanceof Duplex)) return new Duplex(options);
|
|
1112
|
-
Readable.call(this, options);
|
|
1113
|
-
Writable.call(this, options);
|
|
1114
|
-
if (options) {
|
|
1115
|
-
this.allowHalfOpen = options.allowHalfOpen !== false;
|
|
1116
|
-
if (options.readable === false) {
|
|
1117
|
-
this._readableState.readable = false;
|
|
1118
|
-
this._readableState.ended = this._readableState.endEmitted = true;
|
|
1119
|
-
}
|
|
1120
|
-
if (options.writable === false) {
|
|
1121
|
-
this._writableState.writable = false;
|
|
1122
|
-
this._writableState.ending = this._writableState.ended = this._writableState.finished = true;
|
|
1123
|
-
}
|
|
1124
|
-
} else {
|
|
1125
|
-
this.allowHalfOpen = true;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
Object.setPrototypeOf(Duplex.prototype, Readable.prototype);
|
|
1129
|
-
Object.setPrototypeOf(Duplex, Readable);
|
|
1130
|
-
for (const key of Object.getOwnPropertyNames(Writable.prototype)) {
|
|
1131
|
-
if (key === "constructor" || key === "destroy" || key === "_destroy" || Object.prototype.hasOwnProperty.call(Duplex.prototype, key)) continue;
|
|
1132
|
-
if (key === "destroyed" || key === "errored" || key === "closed") continue;
|
|
1133
|
-
Object.defineProperty(Duplex.prototype, key, Object.getOwnPropertyDescriptor(Writable.prototype, key));
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
export function Transform(options) {
|
|
1137
|
-
if (!(this instanceof Transform)) return new Transform(options);
|
|
1138
|
-
Duplex.call(this, options);
|
|
1139
|
-
this._readableState.sync = false;
|
|
1140
|
-
this._transformCallback = null;
|
|
1141
|
-
if (options) {
|
|
1142
|
-
if (typeof options.transform === "function") this._transform = options.transform;
|
|
1143
|
-
if (typeof options.flush === "function") this._flush = options.flush;
|
|
1144
|
-
}
|
|
1145
|
-
this.on("prefinish", transformPrefinish);
|
|
1146
|
-
}
|
|
1147
|
-
Object.setPrototypeOf(Transform.prototype, Duplex.prototype);
|
|
1148
|
-
Object.setPrototypeOf(Transform, Duplex);
|
|
1149
|
-
|
|
1150
|
-
/* _flush, then the end of the readable side; cb is absent when it runs on 'prefinish' because a
|
|
1151
|
-
* subclass replaced _final (zlib's streams do) */
|
|
1152
|
-
function transformFinal(cb) {
|
|
1153
|
-
if (typeof this._flush === "function" && !this.destroyed) {
|
|
1154
|
-
this._flush((er, data) => {
|
|
1155
|
-
if (er) {
|
|
1156
|
-
if (cb) cb(er);
|
|
1157
|
-
else this.destroy(er);
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
if (data !== null && data !== undefined) this.push(data);
|
|
1161
|
-
this.push(null);
|
|
1162
|
-
if (cb) cb();
|
|
1163
|
-
});
|
|
1164
|
-
} else {
|
|
1165
|
-
this.push(null);
|
|
1166
|
-
if (cb) cb();
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
function transformPrefinish() {
|
|
1171
|
-
if (this._final !== transformFinal) transformFinal.call(this);
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
Transform.prototype._final = transformFinal;
|
|
1175
|
-
|
|
1176
|
-
Transform.prototype._transform = function () {
|
|
1177
|
-
throw codeError(Error, "The _transform() method is not implemented", "ERR_METHOD_NOT_IMPLEMENTED");
|
|
1178
|
-
};
|
|
1179
|
-
|
|
1180
|
-
Transform.prototype._write = function (chunk, encoding, callback) {
|
|
1181
|
-
const rState = this._readableState;
|
|
1182
|
-
const wState = this._writableState;
|
|
1183
|
-
const length = rState.length;
|
|
1184
|
-
this._transform(chunk, encoding, (err, val) => {
|
|
1185
|
-
if (err) {
|
|
1186
|
-
callback(err);
|
|
1187
|
-
return;
|
|
1188
|
-
}
|
|
1189
|
-
if (val !== null && val !== undefined) this.push(val);
|
|
1190
|
-
if (rState.ended) nextTick(callback);
|
|
1191
|
-
else if (wState.ended || length === rState.length || rState.length < rState.highWaterMark) callback();
|
|
1192
|
-
else this._transformCallback = callback;
|
|
1
|
+
// node:stream, as Node's lib/stream.js: the legacy Stream with Readable, Writable, Duplex,
|
|
2
|
+
// Transform, PassThrough, pipeline, finished and the rest on it, from the port of Node's
|
|
3
|
+
// lib/internal/streams in internal/streams/. The operators (map, filter, …), compose,
|
|
4
|
+
// Duplex.from, duplexPair and the conversions to and from web streams are modules of their own,
|
|
5
|
+
// linked into programs that name them (internal/features.js, implicitModules in node/index.ts).
|
|
6
|
+
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
7
|
+
import { Buffer } from "./buffer.js";
|
|
8
|
+
import { feature, lazyConstructor, lazyFunction } from "./internal/features.js";
|
|
9
|
+
import { addAbortSignal } from "./internal/streams/add_abort_signal.js";
|
|
10
|
+
import { destroyer } from "./internal/streams/destroy.js";
|
|
11
|
+
import { Duplex } from "./internal/streams/duplex.js";
|
|
12
|
+
import { eos, finished as eosFinished } from "./internal/streams/end_of_stream.js";
|
|
13
|
+
import { Stream } from "./internal/streams/legacy.js";
|
|
14
|
+
import { Readable } from "./internal/streams/readable.js";
|
|
15
|
+
import { getDefaultHighWaterMark, setDefaultHighWaterMark } from "./internal/streams/state.js";
|
|
16
|
+
import { isDestroyed, isDisturbed, isErrored, isIterable, isNodeStream, isReadable, isWebStream, isWritable } from "./internal/streams/utils.js";
|
|
17
|
+
import { Writable } from "./internal/streams/writable.js";
|
|
18
|
+
|
|
19
|
+
const customPromisify = Symbol.for("nodejs.util.promisify.custom");
|
|
20
|
+
|
|
21
|
+
/* stream/promises (lib/stream/promises.js) */
|
|
22
|
+
function promisesPipeline(...streams) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let signal;
|
|
25
|
+
let end;
|
|
26
|
+
const lastArg = streams[streams.length - 1];
|
|
27
|
+
if (lastArg && typeof lastArg === "object" && !isNodeStream(lastArg) && !isIterable(lastArg) && !isWebStream(lastArg)) {
|
|
28
|
+
const options = streams.pop();
|
|
29
|
+
signal = options.signal;
|
|
30
|
+
end = options.end;
|
|
31
|
+
}
|
|
32
|
+
feature("pipelineImpl")(streams, (err, value) => {
|
|
33
|
+
if (err) reject(err);
|
|
34
|
+
else resolve(value);
|
|
35
|
+
}, { signal, end });
|
|
1193
36
|
});
|
|
1194
|
-
};
|
|
1195
|
-
|
|
1196
|
-
Transform.prototype._read = function () {
|
|
1197
|
-
if (this._transformCallback) {
|
|
1198
|
-
const callback = this._transformCallback;
|
|
1199
|
-
this._transformCallback = null;
|
|
1200
|
-
callback();
|
|
1201
|
-
}
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
export function PassThrough(options) {
|
|
1205
|
-
if (!(this instanceof PassThrough)) return new PassThrough(options);
|
|
1206
|
-
Transform.call(this, options);
|
|
1207
|
-
}
|
|
1208
|
-
Object.setPrototypeOf(PassThrough.prototype, Transform.prototype);
|
|
1209
|
-
Object.setPrototypeOf(PassThrough, Transform);
|
|
1210
|
-
PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
|
1211
|
-
cb(null, chunk);
|
|
1212
|
-
};
|
|
1213
|
-
|
|
1214
|
-
/* ---- finished, pipeline, addAbortSignal ------------------------------------------------------ */
|
|
1215
|
-
|
|
1216
|
-
export function finished(stream, options, callback) {
|
|
1217
|
-
if (typeof options === "function") {
|
|
1218
|
-
callback = options;
|
|
1219
|
-
options = {};
|
|
1220
|
-
}
|
|
1221
|
-
options = options || {};
|
|
1222
|
-
let called = false;
|
|
1223
|
-
const done = (err) => {
|
|
1224
|
-
if (called) return;
|
|
1225
|
-
called = true;
|
|
1226
|
-
cleanup();
|
|
1227
|
-
callback.call(stream, err);
|
|
1228
|
-
};
|
|
1229
|
-
const r = stream._readableState;
|
|
1230
|
-
const w = stream._writableState;
|
|
1231
|
-
const readable = options.readable ?? (r !== undefined && r.readable !== false);
|
|
1232
|
-
const writable = options.writable ?? (w !== undefined && w.writable !== false);
|
|
1233
|
-
let readableFinished = !r || r.endEmitted;
|
|
1234
|
-
let writableFinished = !w || w.finished;
|
|
1235
|
-
const onfinish = () => {
|
|
1236
|
-
writableFinished = true;
|
|
1237
|
-
if (!readable || readableFinished) done();
|
|
1238
|
-
};
|
|
1239
|
-
const onend = () => {
|
|
1240
|
-
readableFinished = true;
|
|
1241
|
-
if (!writable || writableFinished) done();
|
|
1242
|
-
};
|
|
1243
|
-
const onerror = (err) => done(err);
|
|
1244
|
-
const onclose = () => {
|
|
1245
|
-
if (readable && !readableFinished && !(r && r.endEmitted)) return done(prematureClose());
|
|
1246
|
-
if (writable && !writableFinished && !(w && w.finished)) return done(prematureClose());
|
|
1247
|
-
done();
|
|
1248
|
-
};
|
|
1249
|
-
const onrequest = () => stream.req && stream.req.on("finish", onfinish);
|
|
1250
|
-
stream.on("end", onend);
|
|
1251
|
-
stream.on("finish", onfinish);
|
|
1252
|
-
stream.on("error", onerror);
|
|
1253
|
-
stream.on("close", onclose);
|
|
1254
|
-
if (stream.req) onrequest();
|
|
1255
|
-
function cleanup() {
|
|
1256
|
-
stream.removeListener("end", onend);
|
|
1257
|
-
stream.removeListener("finish", onfinish);
|
|
1258
|
-
stream.removeListener("error", onerror);
|
|
1259
|
-
stream.removeListener("close", onclose);
|
|
1260
|
-
}
|
|
1261
|
-
const errored = (w && w.errored) || (r && r.errored);
|
|
1262
|
-
if (errored) nextTick(done, errored);
|
|
1263
|
-
else if ((w && w.closeEmitted) || (r && r.closeEmitted)) nextTick(onclose);
|
|
1264
|
-
else if ((!readable || readableFinished) && (!writable || writableFinished) && (r || w)) nextTick(done);
|
|
1265
|
-
return cleanup;
|
|
1266
37
|
}
|
|
38
|
+
export const promises = { finished: eosFinished, pipeline: promisesPipeline };
|
|
1267
39
|
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return s;
|
|
1277
|
-
});
|
|
1278
|
-
let error;
|
|
1279
|
-
let remaining = streams.length;
|
|
1280
|
-
const destroys = [];
|
|
1281
|
-
const finish = (err) => {
|
|
1282
|
-
if (err && !error) {
|
|
1283
|
-
error = err;
|
|
1284
|
-
for (const d of destroys) d(err);
|
|
1285
|
-
}
|
|
1286
|
-
if (--remaining === 0 && callback) callback(error);
|
|
1287
|
-
};
|
|
1288
|
-
for (let i = 0; i < streams.length; i++) {
|
|
1289
|
-
const s = streams[i];
|
|
1290
|
-
const reading = i < streams.length - 1;
|
|
1291
|
-
const writing = i > 0;
|
|
1292
|
-
finished(s, { readable: reading, writable: writing }, (err) => finish(err));
|
|
1293
|
-
destroys.push((err) => {
|
|
1294
|
-
if (!s.destroyed) s.destroy(err);
|
|
1295
|
-
});
|
|
1296
|
-
if (reading) s.pipe(streams[i + 1]);
|
|
1297
|
-
}
|
|
1298
|
-
return streams[streams.length - 1];
|
|
1299
|
-
}
|
|
40
|
+
/* the rarer parts, modules of their own linked into programs that name them: pipeline
|
|
41
|
+
* (internal/stream_pipeline.js), Transform and PassThrough (internal/stream_transform.js),
|
|
42
|
+
* compose and duplexPair (internal/stream_compose.js) */
|
|
43
|
+
export const pipeline = lazyFunction("pipeline");
|
|
44
|
+
export const Transform = lazyConstructor("Transform");
|
|
45
|
+
export const PassThrough = lazyConstructor("PassThrough");
|
|
46
|
+
export const compose = lazyFunction("compose");
|
|
47
|
+
export const duplexPair = lazyFunction("duplexPair");
|
|
1300
48
|
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
export const promises = {
|
|
1309
|
-
pipeline(...streams) {
|
|
1310
|
-
return new Promise((resolve, reject) => {
|
|
1311
|
-
const last = streams[streams.length - 1];
|
|
1312
|
-
if (last && typeof last === "object" && !last._readableState && !last._writableState && !last.pipe && !last.getReader) streams.pop();
|
|
1313
|
-
pipeline(...streams, (err) => (err ? reject(err) : resolve()));
|
|
1314
|
-
});
|
|
1315
|
-
},
|
|
1316
|
-
finished(stream, opts) {
|
|
1317
|
-
return new Promise((resolve, reject) => finished(stream, opts || {}, (err) => (err ? reject(err) : resolve())));
|
|
1318
|
-
},
|
|
1319
|
-
};
|
|
1320
|
-
|
|
1321
|
-
export function isReadable(stream) {
|
|
1322
|
-
return !!(stream && stream._readableState && stream.readable);
|
|
1323
|
-
}
|
|
1324
|
-
export function isErrored(stream) {
|
|
1325
|
-
return !!(stream && ((stream._readableState && stream._readableState.errored) || (stream._writableState && stream._writableState.errored)));
|
|
1326
|
-
}
|
|
1327
|
-
export function isDisturbed(stream) {
|
|
1328
|
-
return !!(stream && stream._readableState && (stream._readableState.dataEmitted || stream._readableState.endEmitted || stream.readableDidRead));
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
Stream.Stream = Stream;
|
|
49
|
+
Stream.isDestroyed = isDestroyed;
|
|
50
|
+
Stream.isDisturbed = isDisturbed;
|
|
51
|
+
Stream.isErrored = isErrored;
|
|
52
|
+
Stream.isReadable = isReadable;
|
|
53
|
+
Stream.isWritable = isWritable;
|
|
1332
54
|
Stream.Readable = Readable;
|
|
1333
55
|
Stream.Writable = Writable;
|
|
1334
56
|
Stream.Duplex = Duplex;
|
|
1335
57
|
Stream.Transform = Transform;
|
|
1336
58
|
Stream.PassThrough = PassThrough;
|
|
59
|
+
Stream.duplexPair = duplexPair;
|
|
1337
60
|
Stream.pipeline = pipeline;
|
|
1338
|
-
Stream.finished = finished;
|
|
1339
61
|
Stream.addAbortSignal = addAbortSignal;
|
|
1340
|
-
Stream.
|
|
1341
|
-
Stream.
|
|
1342
|
-
Stream.
|
|
1343
|
-
Stream.
|
|
62
|
+
Stream.finished = eos;
|
|
63
|
+
Stream.destroy = destroyer;
|
|
64
|
+
Stream.compose = compose;
|
|
65
|
+
Stream.setDefaultHighWaterMark = setDefaultHighWaterMark;
|
|
66
|
+
Stream.getDefaultHighWaterMark = getDefaultHighWaterMark;
|
|
67
|
+
Object.defineProperty(Stream, "promises", { __proto__: null, configurable: true, enumerable: true, get: () => promises });
|
|
68
|
+
Object.defineProperty(pipeline, customPromisify, { __proto__: null, enumerable: true, get: () => promises.pipeline });
|
|
69
|
+
Object.defineProperty(eos, customPromisify, { __proto__: null, enumerable: true, get: () => promises.finished });
|
|
70
|
+
|
|
71
|
+
/* backwards compatibility with node 0.4.x */
|
|
72
|
+
Stream.Stream = Stream;
|
|
73
|
+
Stream._isArrayBufferView = ArrayBuffer.isView;
|
|
74
|
+
Stream._isUint8Array = (value) => value instanceof Uint8Array;
|
|
75
|
+
Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) {
|
|
76
|
+
return Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
77
|
+
};
|
|
1344
78
|
|
|
79
|
+
export {
|
|
80
|
+
addAbortSignal, destroyer as destroy, Duplex, eos as finished, getDefaultHighWaterMark, isDestroyed, isDisturbed, isErrored, isReadable,
|
|
81
|
+
isWritable, Readable, setDefaultHighWaterMark, Stream, Writable,
|
|
82
|
+
};
|
|
1345
83
|
export default Stream;
|