cf-workers-native 0.0.0-stage → 0.1.2-beta.local.sha2f5e4e6956f4
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/LICENSE +21 -0
- package/Package.swift +25 -0
- package/README.md +92 -2
- package/dist/android.d.ts +2 -0
- package/dist/android.js +1 -0
- package/dist/browser/abort/index.d.ts +13 -0
- package/dist/browser/abort/index.js +66 -0
- package/dist/browser/body/index.d.ts +24 -0
- package/dist/browser/body/index.js +116 -0
- package/dist/browser/body/stream-body.d.ts +13 -0
- package/dist/browser/body/stream-body.js +84 -0
- package/dist/browser/documents/body.d.ts +3 -0
- package/dist/browser/documents/body.js +48 -0
- package/dist/browser/documents/form-body.d.ts +1 -0
- package/dist/browser/documents/form-body.js +54 -0
- package/dist/browser/documents/host.d.ts +11 -0
- package/dist/browser/documents/host.js +256 -0
- package/dist/browser/documents/links-source.d.ts +1 -0
- package/dist/browser/documents/links-source.js +1 -0
- package/dist/browser/documents/links.d.ts +1 -0
- package/dist/browser/documents/links.js +33 -0
- package/dist/browser/documents/page-config.d.ts +5 -0
- package/dist/browser/documents/page-config.js +5 -0
- package/dist/browser/documents/page-source.d.ts +1 -0
- package/dist/browser/documents/page-source.js +1 -0
- package/dist/browser/documents/page.d.ts +2 -0
- package/dist/browser/documents/page.js +153 -0
- package/dist/browser/documents/registration.d.ts +5 -0
- package/dist/browser/documents/registration.js +75 -0
- package/dist/browser/documents/runtime.d.ts +7 -0
- package/dist/browser/documents/runtime.js +161 -0
- package/dist/browser/documents/service-worker.js +285 -0
- package/dist/browser/encoding/index.d.ts +7 -0
- package/dist/browser/encoding/index.js +3 -0
- package/dist/browser/fetch/LICENSE-3RD-PARTY.md +9 -0
- package/dist/browser/fetch/LICENSE-APACHE +177 -0
- package/dist/browser/fetch/host-call.d.ts +3 -0
- package/dist/browser/fetch/host-call.js +67 -0
- package/dist/browser/fetch/index.d.ts +5 -0
- package/dist/browser/fetch/index.js +96 -0
- package/dist/browser/fetch/interop.d.ts +6 -0
- package/dist/browser/fetch/interop.js +48 -0
- package/dist/browser/fetch/native-network.d.ts +20 -0
- package/dist/browser/fetch/native-network.js +233 -0
- package/dist/browser/fetch/outbound.d.ts +2 -0
- package/dist/browser/fetch/outbound.js +11 -0
- package/dist/browser/fetch/relay.d.ts +7 -0
- package/dist/browser/fetch/relay.js +100 -0
- package/dist/browser/fetch/scope.d.ts +8 -0
- package/dist/browser/fetch/scope.js +108 -0
- package/dist/browser/fetch/transport.d.ts +39 -0
- package/dist/browser/fetch/transport.js +136 -0
- package/dist/browser/headers/LICENSE-3RD-PARTY.md +9 -0
- package/dist/browser/headers/LICENSE-APACHE +177 -0
- package/dist/browser/headers/index.d.ts +20 -0
- package/dist/browser/headers/index.js +194 -0
- package/dist/browser/isolated/bridge.d.ts +8 -0
- package/dist/browser/isolated/bridge.js +267 -0
- package/dist/browser/isolated/protocol.d.ts +40 -0
- package/dist/browser/isolated/protocol.js +1 -0
- package/dist/browser/isolated/transport.d.ts +2 -0
- package/dist/browser/isolated/transport.js +157 -0
- package/dist/browser/request/LICENSE-3RD-PARTY.md +10 -0
- package/dist/browser/request/LICENSE-APACHE +177 -0
- package/dist/browser/request/index.d.ts +48 -0
- package/dist/browser/request/index.js +182 -0
- package/dist/browser/response/LICENSE-3RD-PARTY.md +10 -0
- package/dist/browser/response/LICENSE-APACHE +177 -0
- package/dist/browser/response/index.d.ts +43 -0
- package/dist/browser/response/index.js +192 -0
- package/dist/browser/response/status.d.ts +1 -0
- package/dist/browser/response/status.js +75 -0
- package/dist/browser/structured-clone/index.d.ts +1 -0
- package/dist/browser/structured-clone/index.js +479 -0
- package/dist/cloudflare/apis/cloudflare-node/index.d.ts +18 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +150 -0
- package/dist/cloudflare/apis/cloudflare-workers/index.d.ts +8 -0
- package/dist/cloudflare/apis/cloudflare-workers/index.js +37 -0
- package/dist/cloudflare/apis/types.d.ts +7 -0
- package/dist/cloudflare/apis/types.js +1 -0
- package/dist/cloudflare/bindings/config.d.ts +42 -0
- package/dist/cloudflare/bindings/config.js +280 -0
- package/dist/cloudflare/bindings/kv/contract.d.ts +6 -0
- package/dist/cloudflare/bindings/kv/contract.js +181 -0
- package/dist/cloudflare/bindings/kv/index.d.ts +18 -0
- package/dist/cloudflare/bindings/kv/index.js +61 -0
- package/dist/cloudflare/bindings/kv/storage.d.ts +25 -0
- package/dist/cloudflare/bindings/kv/storage.js +320 -0
- package/dist/cloudflare/bindings/kv/types.d.ts +50 -0
- package/dist/cloudflare/bindings/kv/types.js +1 -0
- package/dist/cloudflare/bindings/remote.d.ts +8 -0
- package/dist/cloudflare/bindings/remote.js +261 -0
- package/dist/cloudflare/workers/contract.d.ts +8 -0
- package/dist/cloudflare/workers/contract.js +65 -0
- package/dist/cloudflare/workers/feature.d.ts +10 -0
- package/dist/cloudflare/workers/feature.js +28 -0
- package/dist/cloudflare/workers/runtime.d.ts +23 -0
- package/dist/cloudflare/workers/runtime.js +121 -0
- package/dist/cloudflare/workers/types.d.ts +49 -0
- package/dist/cloudflare/workers/types.js +1 -0
- package/dist/cloudflare/workers/worker-runtime.d.ts +44 -0
- package/dist/cloudflare/workers/worker-runtime.js +267 -0
- package/dist/compat/assert/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/assert/LICENSE-APACHE +177 -0
- package/dist/compat/assert/assertion-error.d.ts +26 -0
- package/dist/compat/assert/assertion-error.js +468 -0
- package/dist/compat/assert/diff.d.ts +26 -0
- package/dist/compat/assert/diff.js +329 -0
- package/dist/compat/assert/errors.d.ts +11 -0
- package/dist/compat/assert/errors.js +55 -0
- package/dist/compat/assert/index.cjs +24 -0
- package/dist/compat/assert/index.d.cts +43 -0
- package/dist/compat/assert/index.d.ts +50 -0
- package/dist/compat/assert/index.js +858 -0
- package/dist/compat/async-hooks/LICENSE-APACHE +177 -0
- package/dist/compat/async-hooks/NOTICE.md +8 -0
- package/dist/compat/async-hooks/callbacks.d.ts +7 -0
- package/dist/compat/async-hooks/callbacks.js +18 -0
- package/dist/compat/async-hooks/hooks.d.ts +10 -0
- package/dist/compat/async-hooks/hooks.js +111 -0
- package/dist/compat/async-hooks/index.d.ts +41 -0
- package/dist/compat/async-hooks/index.js +298 -0
- package/dist/compat/buffer/LICENSE-3RD-PARTY.md +15 -0
- package/dist/compat/buffer/LICENSE-APACHE +177 -0
- package/dist/compat/buffer/blob.d.ts +22 -0
- package/dist/compat/buffer/blob.js +210 -0
- package/dist/compat/buffer/bytes.d.ts +34 -0
- package/dist/compat/buffer/bytes.js +228 -0
- package/dist/compat/buffer/errors.d.ts +41 -0
- package/dist/compat/buffer/errors.js +265 -0
- package/dist/compat/buffer/index.d.ts +25 -0
- package/dist/compat/buffer/index.js +24 -0
- package/dist/compat/buffer/internal-buffer.d.ts +148 -0
- package/dist/compat/buffer/internal-buffer.js +1809 -0
- package/dist/compat/buffer/support.d.ts +13 -0
- package/dist/compat/buffer/support.js +65 -0
- package/dist/compat/child-process/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/child-process/LICENSE-APACHE +177 -0
- package/dist/compat/child-process/errors.d.ts +4 -0
- package/dist/compat/child-process/errors.js +6 -0
- package/dist/compat/child-process/index.d.ts +49 -0
- package/dist/compat/child-process/index.js +96 -0
- package/dist/compat/cluster/LICENSE-3RD-PARTY.md +40 -0
- package/dist/compat/cluster/LICENSE-APACHE +177 -0
- package/dist/compat/cluster/errors.d.ts +4 -0
- package/dist/compat/cluster/errors.js +6 -0
- package/dist/compat/cluster/index.d.ts +47 -0
- package/dist/compat/cluster/index.js +88 -0
- package/dist/compat/constants/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/constants/LICENSE-APACHE +177 -0
- package/dist/compat/constants/index.d.ts +481 -0
- package/dist/compat/constants/index.js +488 -0
- package/dist/compat/dgram/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/dgram/LICENSE-APACHE +177 -0
- package/dist/compat/dgram/index.d.ts +10 -0
- package/dist/compat/dgram/index.js +132 -0
- package/dist/compat/diagnostics-channel/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/diagnostics-channel/LICENSE-APACHE +177 -0
- package/dist/compat/diagnostics-channel/index.d.ts +73 -0
- package/dist/compat/diagnostics-channel/index.js +261 -0
- package/dist/compat/diagnostics-channel/native.d.ts +26 -0
- package/dist/compat/diagnostics-channel/native.js +154 -0
- package/dist/compat/dns/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/dns/LICENSE-APACHE +177 -0
- package/dist/compat/dns/client.d.ts +72 -0
- package/dist/compat/dns/client.js +161 -0
- package/dist/compat/dns/constants.d.ts +27 -0
- package/dist/compat/dns/constants.js +31 -0
- package/dist/compat/dns/errors.d.ts +8 -0
- package/dist/compat/dns/errors.js +12 -0
- package/dist/compat/dns/index.d.ts +97 -0
- package/dist/compat/dns/index.js +127 -0
- package/dist/compat/dns/parser.d.ts +18 -0
- package/dist/compat/dns/parser.js +144 -0
- package/dist/compat/dns/promise-resolver.d.ts +82 -0
- package/dist/compat/dns/promise-resolver.js +113 -0
- package/dist/compat/dns/promises.d.ts +50 -0
- package/dist/compat/dns/promises.js +53 -0
- package/dist/compat/dns/resolver.d.ts +34 -0
- package/dist/compat/dns/resolver.js +415 -0
- package/dist/compat/domain/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/domain/LICENSE-APACHE +177 -0
- package/dist/compat/domain/index.d.ts +22 -0
- package/dist/compat/domain/index.js +79 -0
- package/dist/compat/fs/index.d.ts +85 -0
- package/dist/compat/fs/index.js +255 -0
- package/dist/compat/fs/promises/index.d.ts +3 -0
- package/dist/compat/fs/promises/index.js +3 -0
- package/dist/compat/http/index.d.ts +322 -0
- package/dist/compat/http/index.js +1356 -0
- package/dist/compat/http/registry.d.ts +19 -0
- package/dist/compat/http/registry.js +13 -0
- package/dist/compat/http-agent/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-agent/LICENSE-APACHE +177 -0
- package/dist/compat/http-agent/index.d.ts +7 -0
- package/dist/compat/http-agent/index.js +10 -0
- package/dist/compat/http-client/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-client/LICENSE-APACHE +177 -0
- package/dist/compat/http-client/index.d.ts +6 -0
- package/dist/compat/http-client/index.js +7 -0
- package/dist/compat/http-incoming/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-incoming/LICENSE-APACHE +177 -0
- package/dist/compat/http-incoming/index.d.ts +6 -0
- package/dist/compat/http-incoming/index.js +9 -0
- package/dist/compat/http2/LICENSE-3RD-PARTY.md +29 -0
- package/dist/compat/http2/LICENSE-APACHE +177 -0
- package/dist/compat/http2/constants.d.ts +255 -0
- package/dist/compat/http2/constants.js +515 -0
- package/dist/compat/http2/errors.d.ts +4 -0
- package/dist/compat/http2/errors.js +6 -0
- package/dist/compat/http2/index.d.ts +283 -0
- package/dist/compat/http2/index.js +68 -0
- package/dist/compat/https/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/https/LICENSE-APACHE +177 -0
- package/dist/compat/https/agent.d.ts +10 -0
- package/dist/compat/https/agent.js +99 -0
- package/dist/compat/https/errors.d.ts +4 -0
- package/dist/compat/https/errors.js +6 -0
- package/dist/compat/https/index.d.ts +20 -0
- package/dist/compat/https/index.js +50 -0
- package/dist/compat/https/server.d.ts +8 -0
- package/dist/compat/https/server.js +27 -0
- package/dist/compat/immediate/index.d.ts +11 -0
- package/dist/compat/immediate/index.js +58 -0
- package/dist/compat/inspector/LICENSE-3RD-PARTY.md +34 -0
- package/dist/compat/inspector/LICENSE-APACHE +177 -0
- package/dist/compat/inspector/errors.d.ts +4 -0
- package/dist/compat/inspector/errors.js +6 -0
- package/dist/compat/inspector/index.d.ts +18 -0
- package/dist/compat/inspector/index.js +117 -0
- package/dist/compat/inspector/promises.d.ts +18 -0
- package/dist/compat/inspector/promises.js +114 -0
- package/dist/compat/module/index.cjs +2 -0
- package/dist/compat/module/index.d.cts +2 -0
- package/dist/compat/module/index.d.ts +11 -0
- package/dist/compat/module/index.js +44 -0
- package/dist/compat/module/resolve-unavailable.d.ts +1 -0
- package/dist/compat/module/resolve-unavailable.js +3 -0
- package/dist/compat/net/LICENSE-3RD-PARTY.md +15 -0
- package/dist/compat/net/LICENSE-APACHE +177 -0
- package/dist/compat/net/error-base.d.ts +14 -0
- package/dist/compat/net/error-base.js +62 -0
- package/dist/compat/net/errors.d.ts +76 -0
- package/dist/compat/net/errors.js +333 -0
- package/dist/compat/net/index.d.ts +23 -0
- package/dist/compat/net/index.js +46 -0
- package/dist/compat/net/internal-net.d.ts +236 -0
- package/dist/compat/net/internal-net.js +2292 -0
- package/dist/compat/net/ports.d.ts +32 -0
- package/dist/compat/net/ports.js +149 -0
- package/dist/compat/net/reader.d.ts +8 -0
- package/dist/compat/net/reader.js +36 -0
- package/dist/compat/net/sockets.d.ts +20 -0
- package/dist/compat/net/sockets.js +195 -0
- package/dist/compat/net/validators.d.ts +18 -0
- package/dist/compat/net/validators.js +154 -0
- package/dist/compat/os/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/os/LICENSE-APACHE +177 -0
- package/dist/compat/os/index.d.ts +329 -0
- package/dist/compat/os/index.js +278 -0
- package/dist/compat/path/LICENSE-3RD-PARTY.md +35 -0
- package/dist/compat/path/LICENSE-APACHE +177 -0
- package/dist/compat/path/index.d.ts +4 -0
- package/dist/compat/path/index.js +11 -0
- package/dist/compat/path/internal-path.d.ts +95 -0
- package/dist/compat/path/internal-path.js +1542 -0
- package/dist/compat/path/posix/index.d.ts +4 -0
- package/dist/compat/path/posix/index.js +5 -0
- package/dist/compat/path/win32/index.d.ts +4 -0
- package/dist/compat/path/win32/index.js +5 -0
- package/dist/compat/perf-hooks/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/perf-hooks/LICENSE-APACHE +177 -0
- package/dist/compat/perf-hooks/index.d.ts +85 -0
- package/dist/compat/perf-hooks/index.js +79 -0
- package/dist/compat/perf-hooks/performance.d.ts +96 -0
- package/dist/compat/perf-hooks/performance.js +445 -0
- package/dist/compat/punycode/LICENSE-3RD-PARTY.md +7 -0
- package/dist/compat/punycode/LICENSE-APACHE +177 -0
- package/dist/compat/punycode/index.d.ts +93 -0
- package/dist/compat/punycode/index.js +410 -0
- package/dist/compat/querystring/LICENSE-3RD-PARTY.md +35 -0
- package/dist/compat/querystring/LICENSE-APACHE +177 -0
- package/dist/compat/querystring/index.d.ts +14 -0
- package/dist/compat/querystring/index.js +18 -0
- package/dist/compat/querystring/internal-querystring.d.ts +22 -0
- package/dist/compat/querystring/internal-querystring.js +498 -0
- package/dist/compat/readline/LICENSE-3RD-PARTY.md +37 -0
- package/dist/compat/readline/LICENSE-APACHE +177 -0
- package/dist/compat/readline/index.d.ts +21 -0
- package/dist/compat/readline/index.js +56 -0
- package/dist/compat/readline/interface.d.ts +22 -0
- package/dist/compat/readline/interface.js +85 -0
- package/dist/compat/readline/internal-promises.d.ts +32 -0
- package/dist/compat/readline/internal-promises.js +104 -0
- package/dist/compat/readline/promises.d.ts +8 -0
- package/dist/compat/readline/promises.js +32 -0
- package/dist/compat/repl/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/repl/LICENSE-APACHE +177 -0
- package/dist/compat/repl/builtin-modules.d.ts +1 -0
- package/dist/compat/repl/builtin-modules.js +101 -0
- package/dist/compat/repl/errors.d.ts +4 -0
- package/dist/compat/repl/errors.js +6 -0
- package/dist/compat/repl/index.d.ts +53 -0
- package/dist/compat/repl/index.js +106 -0
- package/dist/compat/sqlite/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/sqlite/LICENSE-APACHE +177 -0
- package/dist/compat/sqlite/index.d.ts +12 -0
- package/dist/compat/sqlite/index.js +101 -0
- package/dist/compat/sqlite/native.d.ts +16 -0
- package/dist/compat/sqlite/native.js +33 -0
- package/dist/compat/stream/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream/LICENSE-APACHE +177 -0
- package/dist/compat/stream/add-abort-signal.d.ts +4 -0
- package/dist/compat/stream/add-abort-signal.js +73 -0
- package/dist/compat/stream/compose.d.ts +1 -0
- package/dist/compat/stream/compose.js +313 -0
- package/dist/compat/stream/destroy.d.ts +5 -0
- package/dist/compat/stream/destroy.js +315 -0
- package/dist/compat/stream/duplex.d.ts +48 -0
- package/dist/compat/stream/duplex.js +789 -0
- package/dist/compat/stream/end-of-stream.d.ts +16 -0
- package/dist/compat/stream/end-of-stream.js +269 -0
- package/dist/compat/stream/errors.d.ts +40 -0
- package/dist/compat/stream/errors.js +86 -0
- package/dist/compat/stream/events.d.ts +6 -0
- package/dist/compat/stream/events.js +28 -0
- package/dist/compat/stream/index.cjs +27 -0
- package/dist/compat/stream/index.d.cts +25 -0
- package/dist/compat/stream/index.d.ts +20 -0
- package/dist/compat/stream/index.js +55 -0
- package/dist/compat/stream/legacy.d.ts +8 -0
- package/dist/compat/stream/legacy.js +105 -0
- package/dist/compat/stream/once.d.ts +7 -0
- package/dist/compat/stream/once.js +13 -0
- package/dist/compat/stream/pipeline.d.ts +5 -0
- package/dist/compat/stream/pipeline.js +567 -0
- package/dist/compat/stream/process.d.ts +1 -0
- package/dist/compat/stream/process.js +4 -0
- package/dist/compat/stream/promises.d.ts +7 -0
- package/dist/compat/stream/promises.js +60 -0
- package/dist/compat/stream/readable.d.ts +29 -0
- package/dist/compat/stream/readable.js +2267 -0
- package/dist/compat/stream/state.d.ts +8 -0
- package/dist/compat/stream/state.js +63 -0
- package/dist/compat/stream/transform.d.ts +2 -0
- package/dist/compat/stream/transform.js +202 -0
- package/dist/compat/stream/util.d.ts +55 -0
- package/dist/compat/stream/util.js +345 -0
- package/dist/compat/stream/validators.d.ts +2 -0
- package/dist/compat/stream/validators.js +14 -0
- package/dist/compat/stream/writable.d.ts +21 -0
- package/dist/compat/stream/writable.js +1325 -0
- package/dist/compat/stream-consumers/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/stream-consumers/LICENSE-APACHE +177 -0
- package/dist/compat/stream-consumers/index.d.ts +14 -0
- package/dist/compat/stream-consumers/index.js +62 -0
- package/dist/compat/stream-consumers/iterable.d.ts +1 -0
- package/dist/compat/stream-consumers/iterable.js +34 -0
- package/dist/compat/stream-duplex/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-duplex/LICENSE-APACHE +177 -0
- package/dist/compat/stream-duplex/index.cjs +3 -0
- package/dist/compat/stream-duplex/index.d.cts +2 -0
- package/dist/compat/stream-duplex/index.d.ts +3 -0
- package/dist/compat/stream-duplex/index.js +8 -0
- package/dist/compat/stream-passthrough/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-passthrough/LICENSE-APACHE +177 -0
- package/dist/compat/stream-passthrough/index.cjs +3 -0
- package/dist/compat/stream-passthrough/index.d.cts +2 -0
- package/dist/compat/stream-passthrough/index.d.ts +3 -0
- package/dist/compat/stream-passthrough/index.js +8 -0
- package/dist/compat/stream-promises/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-promises/LICENSE-APACHE +177 -0
- package/dist/compat/stream-promises/index.d.ts +1 -0
- package/dist/compat/stream-promises/index.js +1 -0
- package/dist/compat/stream-readable/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-readable/LICENSE-APACHE +177 -0
- package/dist/compat/stream-readable/index.cjs +3 -0
- package/dist/compat/stream-readable/index.d.cts +2 -0
- package/dist/compat/stream-readable/index.d.ts +3 -0
- package/dist/compat/stream-readable/index.js +8 -0
- package/dist/compat/stream-transform/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-transform/LICENSE-APACHE +177 -0
- package/dist/compat/stream-transform/index.cjs +3 -0
- package/dist/compat/stream-transform/index.d.cts +2 -0
- package/dist/compat/stream-transform/index.d.ts +3 -0
- package/dist/compat/stream-transform/index.js +8 -0
- package/dist/compat/stream-web/LICENSE-MIT +22 -0
- package/dist/compat/stream-web/NOTICE.md +3 -0
- package/dist/compat/stream-web/context.d.ts +2 -0
- package/dist/compat/stream-web/context.js +35 -0
- package/dist/compat/stream-web/index.d.ts +80 -0
- package/dist/compat/stream-web/index.js +129 -0
- package/dist/compat/stream-web/interop.d.ts +6 -0
- package/dist/compat/stream-web/interop.js +72 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -0
- package/dist/compat/stream-web/ponyfill.js +2093 -0
- package/dist/compat/stream-web/runtime.d.ts +16 -0
- package/dist/compat/stream-web/runtime.js +51 -0
- package/dist/compat/stream-writable/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-writable/LICENSE-APACHE +177 -0
- package/dist/compat/stream-writable/index.cjs +3 -0
- package/dist/compat/stream-writable/index.d.cts +2 -0
- package/dist/compat/stream-writable/index.d.ts +3 -0
- package/dist/compat/stream-writable/index.js +8 -0
- package/dist/compat/string-decoder/LICENSE-3RD-PARTY.md +38 -0
- package/dist/compat/string-decoder/LICENSE-APACHE +177 -0
- package/dist/compat/string-decoder/index.d.ts +33 -0
- package/dist/compat/string-decoder/index.js +518 -0
- package/dist/compat/test/LICENSE-3RD-PARTY.md +37 -0
- package/dist/compat/test/LICENSE-APACHE +177 -0
- package/dist/compat/test/index.d.ts +9 -0
- package/dist/compat/test/index.js +11 -0
- package/dist/compat/test/mock.d.ts +103 -0
- package/dist/compat/test/mock.js +397 -0
- package/dist/compat/test/validators.d.ts +2 -0
- package/dist/compat/test/validators.js +14 -0
- package/dist/compat/timers/LICENSE-3RD-PARTY.md +7 -0
- package/dist/compat/timers/LICENSE-APACHE +177 -0
- package/dist/compat/timers/errors.d.ts +28 -0
- package/dist/compat/timers/errors.js +206 -0
- package/dist/compat/timers/host.d.ts +11 -0
- package/dist/compat/timers/host.js +60 -0
- package/dist/compat/timers/index.cjs +3 -0
- package/dist/compat/timers/index.d.cts +23 -0
- package/dist/compat/timers/index.d.ts +36 -0
- package/dist/compat/timers/index.js +20 -0
- package/dist/compat/timers/installation.d.ts +4 -0
- package/dist/compat/timers/installation.js +61 -0
- package/dist/compat/timers/internal-promises.d.ts +19 -0
- package/dist/compat/timers/internal-promises.js +173 -0
- package/dist/compat/timers/promises.cjs +2 -0
- package/dist/compat/timers/promises.d.cts +12 -0
- package/dist/compat/timers/promises.d.ts +14 -0
- package/dist/compat/timers/promises.js +3 -0
- package/dist/compat/timers/timers.d.ts +32 -0
- package/dist/compat/timers/timers.js +147 -0
- package/dist/compat/timers/validation.d.ts +5 -0
- package/dist/compat/timers/validation.js +22 -0
- package/dist/compat/timers/wait.d.ts +4 -0
- package/dist/compat/timers/wait.js +91 -0
- package/dist/compat/tls-common/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-common/LICENSE-APACHE +177 -0
- package/dist/compat/tls-common/index.d.ts +14 -0
- package/dist/compat/tls-common/index.js +88 -0
- package/dist/compat/trace-events/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/trace-events/LICENSE-APACHE +177 -0
- package/dist/compat/trace-events/index.d.ts +18 -0
- package/dist/compat/trace-events/index.js +88 -0
- package/dist/compat/tty/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/tty/LICENSE-APACHE +177 -0
- package/dist/compat/tty/index.d.ts +17 -0
- package/dist/compat/tty/index.js +101 -0
- package/dist/compat/url/LICENSE-3RD-PARTY.md +63 -0
- package/dist/compat/url/LICENSE-ADA +18 -0
- package/dist/compat/url/LICENSE-APACHE +177 -0
- package/dist/compat/url/LICENSE-UNICODE +39 -0
- package/dist/compat/url/LICENSE-WHATWG-URL +21 -0
- package/dist/compat/url/brand.d.ts +4 -0
- package/dist/compat/url/brand.js +10 -0
- package/dist/compat/url/constants.d.ts +27 -0
- package/dist/compat/url/constants.js +28 -0
- package/dist/compat/url/errors.d.ts +44 -0
- package/dist/compat/url/errors.js +248 -0
- package/dist/compat/url/idna-data.d.ts +3958 -0
- package/dist/compat/url/idna-data.js +22 -0
- package/dist/compat/url/idna.d.ts +9 -0
- package/dist/compat/url/idna.js +47 -0
- package/dist/compat/url/index.d.ts +48 -0
- package/dist/compat/url/index.js +39 -0
- package/dist/compat/url/installation.d.ts +4 -0
- package/dist/compat/url/installation.js +61 -0
- package/dist/compat/url/internal-url.d.ts +34 -0
- package/dist/compat/url/internal-url.js +264 -0
- package/dist/compat/url/legacy-url.d.ts +28 -0
- package/dist/compat/url/legacy-url.js +870 -0
- package/dist/compat/url/parser-platform.d.ts +3 -0
- package/dist/compat/url/parser-platform.js +26 -0
- package/dist/compat/url/standard-url.d.ts +2 -0
- package/dist/compat/url/standard-url.js +3189 -0
- package/dist/compat/url/unicode.d.ts +2 -0
- package/dist/compat/url/unicode.js +119 -0
- package/dist/compat/url/validation.d.ts +2 -0
- package/dist/compat/url/validation.js +9 -0
- package/dist/compat/url/web-url.d.ts +27 -0
- package/dist/compat/url/web-url.js +119 -0
- package/dist/compat/util/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/util/LICENSE-APACHE +177 -0
- package/dist/compat/util/additional.d.ts +11 -0
- package/dist/compat/util/additional.js +121 -0
- package/dist/compat/util/comparison-types.d.ts +16 -0
- package/dist/compat/util/comparison-types.js +50 -0
- package/dist/compat/util/comparisons.d.ts +1 -0
- package/dist/compat/util/comparisons.js +527 -0
- package/dist/compat/util/core.d.ts +18 -0
- package/dist/compat/util/core.js +265 -0
- package/dist/compat/util/debuglog.d.ts +1 -0
- package/dist/compat/util/debuglog.js +78 -0
- package/dist/compat/util/index.d.ts +35 -0
- package/dist/compat/util/index.js +77 -0
- package/dist/compat/util/inspect-binding.d.ts +13 -0
- package/dist/compat/util/inspect-binding.js +39 -0
- package/dist/compat/util/inspect-types.d.ts +13 -0
- package/dist/compat/util/inspect-types.js +30 -0
- package/dist/compat/util/inspect.d.ts +152 -0
- package/dist/compat/util/inspect.js +2503 -0
- package/dist/compat/util/mime.d.ts +24 -0
- package/dist/compat/util/mime.js +284 -0
- package/dist/compat/util/properties.d.ts +9 -0
- package/dist/compat/util/properties.js +76 -0
- package/dist/compat/v8/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/v8/LICENSE-APACHE +177 -0
- package/dist/compat/v8/errors.d.ts +5 -0
- package/dist/compat/v8/errors.js +7 -0
- package/dist/compat/v8/index.d.ts +106 -0
- package/dist/compat/v8/index.js +280 -0
- package/dist/compat/vm/LICENSE-3RD-PARTY.md +39 -0
- package/dist/compat/vm/LICENSE-APACHE +177 -0
- package/dist/compat/vm/errors.d.ts +5 -0
- package/dist/compat/vm/errors.js +7 -0
- package/dist/compat/vm/index.d.ts +47 -0
- package/dist/compat/vm/index.js +231 -0
- package/dist/compat/vm/validation.d.ts +3 -0
- package/dist/compat/vm/validation.js +14 -0
- package/dist/compat/wasi/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/wasi/LICENSE-APACHE +177 -0
- package/dist/compat/wasi/errors.d.ts +4 -0
- package/dist/compat/wasi/errors.js +6 -0
- package/dist/compat/wasi/index.d.ts +15 -0
- package/dist/compat/wasi/index.js +44 -0
- package/dist/compat/worker-threads/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/worker-threads/LICENSE-APACHE +177 -0
- package/dist/compat/worker-threads/errors.d.ts +4 -0
- package/dist/compat/worker-threads/errors.js +6 -0
- package/dist/compat/worker-threads/index.d.ts +71 -0
- package/dist/compat/worker-threads/index.js +138 -0
- package/dist/compat/worker-threads/message-channel.d.ts +18 -0
- package/dist/compat/worker-threads/message-channel.js +157 -0
- package/dist/configured.d.ts +3 -0
- package/dist/configured.js +4 -0
- package/dist/environment.d.ts +4 -0
- package/dist/environment.js +18 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +107 -0
- package/dist/ios.d.ts +2 -0
- package/dist/ios.js +1 -0
- package/dist/native-entry.d.ts +8 -0
- package/dist/native-entry.js +67 -0
- package/dist/shared/brotli/LICENSE-APACHE +201 -0
- package/dist/shared/brotli/LICENSE-MIT +9 -0
- package/dist/shared/brotli/NOTICE +3 -0
- package/dist/shared/brotli/index.d.ts +2 -0
- package/dist/shared/brotli/index.js +288 -0
- package/dist/shared/contracts/index.d.ts +42 -0
- package/dist/shared/contracts/index.js +88 -0
- package/dist/shared/contracts/testing.d.ts +22 -0
- package/dist/shared/contracts/testing.js +57 -0
- package/dist/shared/globals/index.d.ts +3 -0
- package/dist/shared/globals/index.js +87 -0
- package/dist/shared/globals/inject.d.ts +2 -0
- package/dist/shared/globals/inject.js +3 -0
- package/dist/shared/globals/install.d.ts +1 -0
- package/dist/shared/globals/install.js +15 -0
- package/dist/shared/globals/node-install.d.ts +1 -0
- package/dist/shared/globals/node-install.js +4 -0
- package/dist/shared/globals/platform.d.ts +104 -0
- package/dist/shared/globals/platform.js +37 -0
- package/dist/shared/globals/runtime.d.ts +6 -0
- package/dist/shared/globals/runtime.js +8 -0
- package/dist/shared/globals/symbols.d.ts +4 -0
- package/dist/shared/globals/symbols.js +35 -0
- package/dist/shared/globals/web.d.ts +4 -0
- package/dist/shared/globals/web.js +108 -0
- package/dist/shared/http-wire/LICENSE.llhttp +22 -0
- package/dist/shared/http-wire/LICENSE.undici +21 -0
- package/dist/shared/http-wire/NOTICE.md +14 -0
- package/dist/shared/http-wire/index.d.ts +27 -0
- package/dist/shared/http-wire/index.js +132 -0
- package/dist/shared/http-wire/wasm.d.ts +2 -0
- package/dist/shared/http-wire/wasm.js +2 -0
- package/dist/tooling/async.d.ts +7 -0
- package/dist/tooling/async.js +99 -0
- package/dist/tooling/build-isolation.d.ts +4 -0
- package/dist/tooling/build-isolation.js +34 -0
- package/dist/tooling/documents.d.ts +7 -0
- package/dist/tooling/documents.js +26 -0
- package/dist/tooling/esbuild.d.ts +15 -0
- package/dist/tooling/esbuild.js +193 -0
- package/dist/tooling/files.d.ts +2 -0
- package/dist/tooling/files.js +18 -0
- package/dist/tooling/opennext/build.d.ts +1 -0
- package/dist/tooling/opennext/build.js +121 -0
- package/dist/tooling/opennext/index.d.ts +3 -0
- package/dist/tooling/opennext/index.js +213 -0
- package/dist/tooling/opennext/plan.d.ts +9 -0
- package/dist/tooling/opennext/plan.js +36 -0
- package/dist/tooling/opennext/safety.d.ts +4 -0
- package/dist/tooling/opennext/safety.js +36 -0
- package/dist/tooling/route-permissions.d.ts +3 -0
- package/dist/tooling/route-permissions.js +15 -0
- package/dist/tooling/server-modules.d.ts +30 -0
- package/dist/tooling/server-modules.js +98 -0
- package/dist/tooling/server-only-html.d.ts +1 -0
- package/dist/tooling/server-only-html.js +66 -0
- package/dist/tooling/server-only.d.ts +6 -0
- package/dist/tooling/server-only.js +53 -0
- package/dist/tooling/server.d.ts +25 -0
- package/dist/tooling/server.js +981 -0
- package/dist/tooling/shared.d.ts +13 -0
- package/dist/tooling/shared.js +130 -0
- package/dist/tooling/vite.d.ts +18 -0
- package/dist/tooling/vite.js +448 -0
- package/dist/tooling/void/index.d.ts +3 -0
- package/dist/tooling/void/index.js +205 -0
- package/dist/tooling/void/plan.d.ts +17 -0
- package/dist/tooling/void/plan.js +288 -0
- package/native/android/build.gradle +68 -0
- package/native/android/consumer-rules.pro +2 -0
- package/native/android/src/main/AndroidManifest.xml +6 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +202 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +256 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNative.java +22 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeActivity.java +178 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeBridge.java +45 -0
- package/native/ios/DocumentBridge.swift +330 -0
- package/native/ios/NetworkBridge.swift +51 -0
- package/native/ios/SocketBridge.swift +180 -0
- package/native/ios/WorkersCapacitorPlugin.swift +152 -0
- package/native/ios-host/WorkersView.swift +194 -0
- package/package.json +154 -4
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
3
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
4
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
5
|
+
//
|
|
6
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
7
|
+
//
|
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
// copy of this software and associated documentation files (the
|
|
10
|
+
// "Software"), to deal in the Software without restriction, including
|
|
11
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
12
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
13
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
14
|
+
// following conditions:
|
|
15
|
+
//
|
|
16
|
+
// The above copyright notice and this permission notice shall be included
|
|
17
|
+
// in all copies or substantial portions of the Software.
|
|
18
|
+
//
|
|
19
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
20
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
21
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
22
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
23
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
24
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
25
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
import { EventEmitter } from "./events.js";
|
|
27
|
+
import { Buffer } from "node:buffer";
|
|
28
|
+
export function Stream(opts) {
|
|
29
|
+
EventEmitter.call(this, opts || {});
|
|
30
|
+
}
|
|
31
|
+
Object.setPrototypeOf(Stream.prototype, EventEmitter.prototype);
|
|
32
|
+
Object.setPrototypeOf(Stream, EventEmitter);
|
|
33
|
+
Stream.prototype.pipe = function (dest, options) {
|
|
34
|
+
const source = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
35
|
+
function ondata(chunk) {
|
|
36
|
+
if (dest.writable && dest.write(chunk) === false && source.pause) {
|
|
37
|
+
source.pause();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
source.on("data", ondata);
|
|
41
|
+
function ondrain() {
|
|
42
|
+
if (source.readable && source.resume) {
|
|
43
|
+
source.resume();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
dest.on("drain", ondrain);
|
|
47
|
+
// If the 'end' option is not supplied, dest.end() will be called when
|
|
48
|
+
// source gets the 'end' or 'close' events. Only dest.end() once.
|
|
49
|
+
if (!dest._isStdio && (!options || options.end !== false)) {
|
|
50
|
+
source.on("end", onend);
|
|
51
|
+
source.on("close", onclose);
|
|
52
|
+
}
|
|
53
|
+
let didOnEnd = false;
|
|
54
|
+
function onend() {
|
|
55
|
+
if (didOnEnd)
|
|
56
|
+
return;
|
|
57
|
+
didOnEnd = true;
|
|
58
|
+
dest.end();
|
|
59
|
+
}
|
|
60
|
+
function onclose() {
|
|
61
|
+
if (didOnEnd)
|
|
62
|
+
return;
|
|
63
|
+
didOnEnd = true;
|
|
64
|
+
if (typeof dest.destroy === "function")
|
|
65
|
+
dest.destroy();
|
|
66
|
+
}
|
|
67
|
+
// Don't leave dangling pipes when there are errors.
|
|
68
|
+
function onerror(er) {
|
|
69
|
+
cleanup();
|
|
70
|
+
if (EventEmitter.listenerCount(this, "error") === 0) {
|
|
71
|
+
this.emit("error", er);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
source.prependListener("error", onerror);
|
|
75
|
+
dest.prependListener("error", onerror);
|
|
76
|
+
// Remove all the event listeners that were added.
|
|
77
|
+
function cleanup() {
|
|
78
|
+
source.removeListener("data", ondata);
|
|
79
|
+
dest.removeListener("drain", ondrain);
|
|
80
|
+
source.removeListener("end", onend);
|
|
81
|
+
source.removeListener("close", onclose);
|
|
82
|
+
source.removeListener("error", onerror);
|
|
83
|
+
dest.removeListener("error", onerror);
|
|
84
|
+
source.removeListener("end", cleanup);
|
|
85
|
+
source.removeListener("close", cleanup);
|
|
86
|
+
dest.removeListener("close", cleanup);
|
|
87
|
+
}
|
|
88
|
+
source.on("end", cleanup);
|
|
89
|
+
source.on("close", cleanup);
|
|
90
|
+
dest.on("close", cleanup);
|
|
91
|
+
dest.emit("pipe", source);
|
|
92
|
+
// Allow for unix-like usage: A.pipe(B).pipe(C)
|
|
93
|
+
return dest;
|
|
94
|
+
};
|
|
95
|
+
// Backwards-compat with node 0.4.x
|
|
96
|
+
Stream.Stream = Stream;
|
|
97
|
+
Stream._isUint8Array = function isUint8Array(value) {
|
|
98
|
+
return value instanceof Uint8Array;
|
|
99
|
+
};
|
|
100
|
+
Stream._isArrayBufferView = function isArrayBufferView(value) {
|
|
101
|
+
return ArrayBuffer.isView(value);
|
|
102
|
+
};
|
|
103
|
+
Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) {
|
|
104
|
+
return Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
105
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
export type IncomingMessageCallback = (req: IncomingMessage) => void;
|
|
3
|
+
interface OnceOptions {
|
|
4
|
+
preserveReturnValue?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function once<RT>(this: unknown, callback: (...allArgs: unknown[]) => RT, options?: OnceOptions): (...all: unknown[]) => RT;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function once(callback, options) {
|
|
2
|
+
const preserveReturnValue = options?.preserveReturnValue ?? false;
|
|
3
|
+
let called = false;
|
|
4
|
+
let returnValue;
|
|
5
|
+
return function (...args) {
|
|
6
|
+
if (called)
|
|
7
|
+
return returnValue;
|
|
8
|
+
called = true;
|
|
9
|
+
const result = Reflect.apply(callback, this, args);
|
|
10
|
+
returnValue = preserveReturnValue ? result : undefined;
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function pipeline(...streams: any[]): any;
|
|
2
|
+
export declare function pipelineImpl(streams: any, callback: any, opts: any): any;
|
|
3
|
+
export declare function pipe(src: any, dst: any, finish: any, finishOnlyHandleError: any, { end }: {
|
|
4
|
+
end: any;
|
|
5
|
+
}): (...args: unknown[]) => void;
|
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { dispose } from "../../shared/globals/symbols.js";
|
|
3
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
4
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
5
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
6
|
+
//
|
|
7
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
8
|
+
//
|
|
9
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
10
|
+
// copy of this software and associated documentation files (the
|
|
11
|
+
// "Software"), to deal in the Software without restriction, including
|
|
12
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
13
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
14
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
15
|
+
// following conditions:
|
|
16
|
+
//
|
|
17
|
+
// The above copyright notice and this permission notice shall be included
|
|
18
|
+
// in all copies or substantial portions of the Software.
|
|
19
|
+
//
|
|
20
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
21
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
22
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
23
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
24
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
25
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
26
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
+
import { isIterable, isReadable, isReadableNodeStream, isNodeStream, isTransformStream, isWebStream, isReadableStream, isWritableStream, isReadableFinished, } from "./util.js";
|
|
28
|
+
import { eos } from "./end-of-stream.js";
|
|
29
|
+
import { destroyer as destroyerImpl } from "./destroy.js";
|
|
30
|
+
import { once } from "./once.js";
|
|
31
|
+
import { addAbortListener } from "./events.js";
|
|
32
|
+
import { nextTick } from "./process.js";
|
|
33
|
+
import { PassThrough } from "./transform.js";
|
|
34
|
+
import { Duplex } from "./duplex.js";
|
|
35
|
+
import { Readable } from "./readable.js";
|
|
36
|
+
import { aggregateTwoErrors, ERR_INVALID_ARG_TYPE, ERR_INVALID_RETURN_VALUE, ERR_MISSING_ARGS, ERR_STREAM_DESTROYED, ERR_STREAM_PREMATURE_CLOSE, AbortError, } from "./errors.js";
|
|
37
|
+
import { validateFunction, validateAbortSignal } from "./validators.js";
|
|
38
|
+
function destroyer(stream, reading, writing) {
|
|
39
|
+
let finished = false;
|
|
40
|
+
stream.on("close", () => {
|
|
41
|
+
finished = true;
|
|
42
|
+
});
|
|
43
|
+
const cleanup = eos(stream, {
|
|
44
|
+
readable: reading,
|
|
45
|
+
writable: writing,
|
|
46
|
+
}, (err) => {
|
|
47
|
+
finished = !err;
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
destroy: (err) => {
|
|
51
|
+
if (finished)
|
|
52
|
+
return;
|
|
53
|
+
finished = true;
|
|
54
|
+
destroyerImpl(stream, err || new ERR_STREAM_DESTROYED("pipe"));
|
|
55
|
+
},
|
|
56
|
+
cleanup,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function popCallback(streams) {
|
|
60
|
+
// Streams should never be an empty array. It should always contain at least
|
|
61
|
+
// a single stream. Therefore optimize for the average case instead of
|
|
62
|
+
// checking for length === 0 as well.
|
|
63
|
+
validateFunction(streams[streams.length - 1], "streams[stream.length - 1]");
|
|
64
|
+
return streams.pop();
|
|
65
|
+
}
|
|
66
|
+
function makeAsyncIterable(val) {
|
|
67
|
+
if (isIterable(val)) {
|
|
68
|
+
return val;
|
|
69
|
+
}
|
|
70
|
+
else if (isReadableNodeStream(val)) {
|
|
71
|
+
// Legacy streams are not Iterable.
|
|
72
|
+
return fromReadable(val);
|
|
73
|
+
}
|
|
74
|
+
throw new ERR_INVALID_ARG_TYPE("val", ["Readable", "Iterable", "AsyncIterable"], val);
|
|
75
|
+
}
|
|
76
|
+
async function* fromReadable(val) {
|
|
77
|
+
yield* Readable.prototype[Symbol.asyncIterator].call(val);
|
|
78
|
+
}
|
|
79
|
+
async function pumpToNode(iterable, writable, finish, { end }) {
|
|
80
|
+
let error;
|
|
81
|
+
let onresolve = null;
|
|
82
|
+
const resume = (err) => {
|
|
83
|
+
if (err) {
|
|
84
|
+
error = err;
|
|
85
|
+
}
|
|
86
|
+
if (onresolve) {
|
|
87
|
+
const callback = onresolve;
|
|
88
|
+
onresolve = null;
|
|
89
|
+
callback();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const wait = () => {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
reject(error);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
onresolve = () => {
|
|
99
|
+
if (error) {
|
|
100
|
+
reject(error);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
resolve();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
writable.on("drain", resume);
|
|
110
|
+
const cleanup = eos(writable, {
|
|
111
|
+
readable: false,
|
|
112
|
+
}, resume);
|
|
113
|
+
try {
|
|
114
|
+
if (writable.writableNeedDrain) {
|
|
115
|
+
await wait();
|
|
116
|
+
}
|
|
117
|
+
for await (const chunk of iterable) {
|
|
118
|
+
if (!writable.write(chunk)) {
|
|
119
|
+
await wait();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (end) {
|
|
123
|
+
writable.end();
|
|
124
|
+
await wait();
|
|
125
|
+
}
|
|
126
|
+
finish();
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
finish(error !== err ? aggregateTwoErrors(error, err) : err);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
cleanup();
|
|
133
|
+
writable.off("drain", resume);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// A web ReadableStream as a pump's source: the async iteration the stream
|
|
137
|
+
// itself offers, but through a reader the pipeline's teardown (destroys) can
|
|
138
|
+
// reach. Nothing can interrupt the stream's own iterator's pending read,
|
|
139
|
+
// whereas cancelling the reader settles it; the iteration then fails with
|
|
140
|
+
// the error the pipeline was torn down with. Leaving the loop early (the
|
|
141
|
+
// destination failed) cancels the stream, as the stream's own iterator
|
|
142
|
+
// would. Written out rather than as an async generator: yield would await a
|
|
143
|
+
// promise-valued chunk, which must reach the destination as it is, and a
|
|
144
|
+
// pending one could not be interrupted. The source's own failure is
|
|
145
|
+
// reported through onError as soon as it happens, as eos() reports a node
|
|
146
|
+
// source's: a pump waiting on its destination's backpressure would
|
|
147
|
+
// otherwise learn of it only at its next read, which a destination that
|
|
148
|
+
// never drains would never let it make.
|
|
149
|
+
function readWeb(readable, destroys, onError) {
|
|
150
|
+
let reader;
|
|
151
|
+
let error;
|
|
152
|
+
let released = false;
|
|
153
|
+
destroys.push((err) => {
|
|
154
|
+
error = err || new ERR_STREAM_DESTROYED("pipe");
|
|
155
|
+
// A source the pump has not started reading is cancelled too: a failed
|
|
156
|
+
// pipeline leaves no stage behind.
|
|
157
|
+
const cancelled = reader === undefined ? readable.cancel(error) : reader.cancel(error);
|
|
158
|
+
cancelled.catch(() => { });
|
|
159
|
+
});
|
|
160
|
+
async function release() {
|
|
161
|
+
if (released || reader === undefined) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
released = true;
|
|
165
|
+
try {
|
|
166
|
+
await reader.cancel(error);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// The stream had already errored.
|
|
170
|
+
}
|
|
171
|
+
reader.releaseLock();
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
[Symbol.asyncIterator]() {
|
|
175
|
+
return this;
|
|
176
|
+
},
|
|
177
|
+
async next() {
|
|
178
|
+
try {
|
|
179
|
+
if (reader === undefined) {
|
|
180
|
+
reader = readable.getReader();
|
|
181
|
+
// The pipeline records the error and tears its stages down,
|
|
182
|
+
// which wakes a pump waiting on the destination; a read in
|
|
183
|
+
// flight rejects with the same error on its own.
|
|
184
|
+
reader.closed.then(undefined, (err) => {
|
|
185
|
+
if (!released) {
|
|
186
|
+
onError(err);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (error === undefined) {
|
|
191
|
+
const result = await reader.read();
|
|
192
|
+
if (error === undefined && !result.done) {
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
await release();
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
await release();
|
|
202
|
+
if (error !== undefined) {
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
return { value: undefined, done: true };
|
|
206
|
+
},
|
|
207
|
+
async return() {
|
|
208
|
+
await release();
|
|
209
|
+
return { value: undefined, done: true };
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async function pumpToWeb(readable, writable, finish, { end, destroys, onError }) {
|
|
214
|
+
if (isTransformStream(writable)) {
|
|
215
|
+
writable = writable.writable;
|
|
216
|
+
}
|
|
217
|
+
// https://streams.spec.whatwg.org/#example-manual-write-with-backpressure
|
|
218
|
+
let writer;
|
|
219
|
+
try {
|
|
220
|
+
writer = writable.getWriter();
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
// A locked destination fails the pump as a failed write would, once the
|
|
224
|
+
// pipeline has finished wiring its stages.
|
|
225
|
+
nextTick(finish, err);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// The pipeline's teardown aborts the destination with the pipeline's
|
|
229
|
+
// error, which also wakes a pump waiting on the writer. A pump that has
|
|
230
|
+
// completed is left alone: with end false its writer stays open.
|
|
231
|
+
let settled = false;
|
|
232
|
+
destroys.push((err) => {
|
|
233
|
+
if (!settled) {
|
|
234
|
+
writer.abort(err || new ERR_STREAM_DESTROYED("pipe")).catch(() => { });
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
// The destination's failure is observed on its own, as eos() observes a
|
|
238
|
+
// node destination's: a pump waiting on an idle source would otherwise
|
|
239
|
+
// learn of a rejected write, or of the sink erroring, only from its next
|
|
240
|
+
// write. The pipeline records the error and tears its stages down, which
|
|
241
|
+
// fails this pump's read; the pump then finishes once, below.
|
|
242
|
+
writer.closed.then(undefined, (err) => {
|
|
243
|
+
if (!settled) {
|
|
244
|
+
onError(err);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
try {
|
|
248
|
+
for await (const chunk of readable) {
|
|
249
|
+
await writer.ready;
|
|
250
|
+
writer.write(chunk).catch(() => { });
|
|
251
|
+
}
|
|
252
|
+
await writer.ready;
|
|
253
|
+
if (end) {
|
|
254
|
+
await writer.close();
|
|
255
|
+
}
|
|
256
|
+
settled = true;
|
|
257
|
+
finish();
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
settled = true;
|
|
261
|
+
try {
|
|
262
|
+
await writer.abort(err);
|
|
263
|
+
finish(err);
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
finish(err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export function pipeline(...streams) {
|
|
271
|
+
return pipelineImpl(streams, once(popCallback(streams)));
|
|
272
|
+
}
|
|
273
|
+
export function pipelineImpl(streams, callback, opts) {
|
|
274
|
+
if (streams.length === 1 && Array.isArray(streams[0])) {
|
|
275
|
+
streams = streams[0];
|
|
276
|
+
}
|
|
277
|
+
if (streams.length < 2) {
|
|
278
|
+
throw new ERR_MISSING_ARGS("streams");
|
|
279
|
+
}
|
|
280
|
+
const ac = new AbortController();
|
|
281
|
+
const signal = ac.signal;
|
|
282
|
+
const outerSignal = opts?.signal;
|
|
283
|
+
// Need to cleanup event listeners if last stream is readable
|
|
284
|
+
// https://github.com/nodejs/node/issues/35452
|
|
285
|
+
const lastStreamCleanup = [];
|
|
286
|
+
validateAbortSignal(outerSignal, "options.signal");
|
|
287
|
+
function abort() {
|
|
288
|
+
finishImpl(new AbortError(undefined, { cause: outerSignal?.reason }));
|
|
289
|
+
}
|
|
290
|
+
let disposable;
|
|
291
|
+
if (outerSignal) {
|
|
292
|
+
disposable = addAbortListener(outerSignal, abort);
|
|
293
|
+
}
|
|
294
|
+
let error;
|
|
295
|
+
let value;
|
|
296
|
+
const destroys = [];
|
|
297
|
+
let finishCount = 0;
|
|
298
|
+
function finish(err) {
|
|
299
|
+
finishImpl(err, --finishCount === 0);
|
|
300
|
+
}
|
|
301
|
+
function finishOnlyHandleError(err) {
|
|
302
|
+
finishImpl(err, false);
|
|
303
|
+
}
|
|
304
|
+
function finishImpl(err, final) {
|
|
305
|
+
if (err && (!error || error.code === "ERR_STREAM_PREMATURE_CLOSE")) {
|
|
306
|
+
error = err;
|
|
307
|
+
}
|
|
308
|
+
if (!error && !final) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
while (destroys.length) {
|
|
312
|
+
destroys.shift()(error);
|
|
313
|
+
}
|
|
314
|
+
disposable?.[dispose]();
|
|
315
|
+
ac.abort();
|
|
316
|
+
if (final) {
|
|
317
|
+
if (!error) {
|
|
318
|
+
lastStreamCleanup.forEach((fn) => fn());
|
|
319
|
+
}
|
|
320
|
+
nextTick(callback, error, value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// Internal, for compose(): a destroyed composition fails its pipeline from
|
|
324
|
+
// the outside with the destroy error, as a failing stage would — every
|
|
325
|
+
// stage is destroyed and the callback reports that error. A no-op once the
|
|
326
|
+
// pipeline has completed (its callback is already on its way).
|
|
327
|
+
opts?.onTeardown?.((err) => {
|
|
328
|
+
finishOnlyHandleError(err || new AbortError());
|
|
329
|
+
});
|
|
330
|
+
let ret;
|
|
331
|
+
for (let i = 0; i < streams.length; i++) {
|
|
332
|
+
const stream = streams[i];
|
|
333
|
+
const reading = i < streams.length - 1;
|
|
334
|
+
const writing = i > 0;
|
|
335
|
+
const end = reading || opts?.end !== false;
|
|
336
|
+
const isLastStream = i === streams.length - 1;
|
|
337
|
+
if (isNodeStream(stream)) {
|
|
338
|
+
if (end) {
|
|
339
|
+
const { destroy, cleanup } = destroyer(stream, reading, writing);
|
|
340
|
+
destroys.push(destroy);
|
|
341
|
+
if (isReadable(stream) && isLastStream) {
|
|
342
|
+
lastStreamCleanup.push(cleanup);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// Catch stream errors that occur after pipe/pump has completed.
|
|
346
|
+
function onError(err) {
|
|
347
|
+
if (err &&
|
|
348
|
+
err.name !== "AbortError" &&
|
|
349
|
+
err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
350
|
+
finishOnlyHandleError(err);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
stream.on("error", onError);
|
|
354
|
+
if (isReadable(stream) && isLastStream) {
|
|
355
|
+
lastStreamCleanup.push(() => {
|
|
356
|
+
stream.removeListener("error", onError);
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (i === 0) {
|
|
361
|
+
if (typeof stream === "function") {
|
|
362
|
+
ret = stream({ signal });
|
|
363
|
+
if (!isIterable(ret)) {
|
|
364
|
+
throw new ERR_INVALID_RETURN_VALUE("Iterable, AsyncIterable or Stream", "source", ret);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else if (isIterable(stream) ||
|
|
368
|
+
isReadableNodeStream(stream) ||
|
|
369
|
+
isTransformStream(stream)) {
|
|
370
|
+
ret = stream;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
ret = Duplex.from(stream);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if (typeof stream === "function") {
|
|
377
|
+
if (isTransformStream(ret)) {
|
|
378
|
+
ret = makeAsyncIterable(ret?.readable);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
ret = makeAsyncIterable(ret);
|
|
382
|
+
}
|
|
383
|
+
ret = stream(ret, { signal });
|
|
384
|
+
if (reading) {
|
|
385
|
+
if (!isIterable(ret, true)) {
|
|
386
|
+
throw new ERR_INVALID_RETURN_VALUE("AsyncIterable", `transform[${i - 1}]`, ret);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
// If the last argument to pipeline is not a stream
|
|
391
|
+
// we must create a proxy stream so that pipeline(...)
|
|
392
|
+
// always returns a stream which can be further
|
|
393
|
+
// composed through `.pipe(stream)`.
|
|
394
|
+
const pt = new PassThrough({
|
|
395
|
+
objectMode: true,
|
|
396
|
+
});
|
|
397
|
+
// Handle Promises/A+ spec, `then` could be a getter that throws on
|
|
398
|
+
// second use.
|
|
399
|
+
const then = ret?.then;
|
|
400
|
+
if (typeof then === "function") {
|
|
401
|
+
finishCount++;
|
|
402
|
+
then.call(ret, (val) => {
|
|
403
|
+
value = val;
|
|
404
|
+
if (val != null) {
|
|
405
|
+
pt.write(val);
|
|
406
|
+
}
|
|
407
|
+
if (end) {
|
|
408
|
+
pt.end();
|
|
409
|
+
}
|
|
410
|
+
nextTick(finish);
|
|
411
|
+
}, (err) => {
|
|
412
|
+
pt.destroy(err);
|
|
413
|
+
nextTick(finish, err);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
else if (isIterable(ret, true)) {
|
|
417
|
+
finishCount++;
|
|
418
|
+
pumpToNode(ret, pt, finish, { end });
|
|
419
|
+
}
|
|
420
|
+
else if (isReadableStream(ret) || isTransformStream(ret)) {
|
|
421
|
+
const toRead = ret.readable || ret;
|
|
422
|
+
finishCount++;
|
|
423
|
+
pumpToNode(readWeb(toRead, destroys, finishOnlyHandleError), pt, finish, { end });
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
throw new ERR_INVALID_RETURN_VALUE("AsyncIterable or Promise", "destination", ret);
|
|
427
|
+
}
|
|
428
|
+
ret = pt;
|
|
429
|
+
const { destroy, cleanup } = destroyer(ret, false, true);
|
|
430
|
+
destroys.push(destroy);
|
|
431
|
+
if (isLastStream) {
|
|
432
|
+
lastStreamCleanup.push(cleanup);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else if (isNodeStream(stream)) {
|
|
437
|
+
if (isReadableNodeStream(ret)) {
|
|
438
|
+
finishCount += 2;
|
|
439
|
+
const cleanup = pipe(ret, stream, finish, finishOnlyHandleError, {
|
|
440
|
+
end,
|
|
441
|
+
});
|
|
442
|
+
if (isReadable(stream) && isLastStream) {
|
|
443
|
+
lastStreamCleanup.push(cleanup);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else if (isTransformStream(ret) || isReadableStream(ret)) {
|
|
447
|
+
const toRead = ret.readable || ret;
|
|
448
|
+
finishCount++;
|
|
449
|
+
pumpToNode(readWeb(toRead, destroys, finishOnlyHandleError), stream, finish, { end });
|
|
450
|
+
}
|
|
451
|
+
else if (isIterable(ret)) {
|
|
452
|
+
finishCount++;
|
|
453
|
+
pumpToNode(ret, stream, finish, { end });
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
throw new ERR_INVALID_ARG_TYPE("val", [
|
|
457
|
+
"Readable",
|
|
458
|
+
"Iterable",
|
|
459
|
+
"AsyncIterable",
|
|
460
|
+
"ReadableStream",
|
|
461
|
+
"TransformStream",
|
|
462
|
+
], ret);
|
|
463
|
+
}
|
|
464
|
+
ret = stream;
|
|
465
|
+
}
|
|
466
|
+
else if (isWebStream(stream)) {
|
|
467
|
+
// A web stage past the head is written to; only a WritableStream, or
|
|
468
|
+
// a TransformStream through its writable, can be.
|
|
469
|
+
if (!isWritableStream(stream) && !isTransformStream(stream)) {
|
|
470
|
+
throw new ERR_INVALID_ARG_TYPE("destination", ["WritableStream", "TransformStream"], stream);
|
|
471
|
+
}
|
|
472
|
+
const pumpOptions = { end, destroys, onError: finishOnlyHandleError };
|
|
473
|
+
if (isReadableNodeStream(ret)) {
|
|
474
|
+
finishCount++;
|
|
475
|
+
pumpToWeb(makeAsyncIterable(ret), stream, finish, pumpOptions);
|
|
476
|
+
}
|
|
477
|
+
else if (isReadableStream(ret)) {
|
|
478
|
+
finishCount++;
|
|
479
|
+
pumpToWeb(readWeb(ret, destroys, finishOnlyHandleError), stream, finish, pumpOptions);
|
|
480
|
+
}
|
|
481
|
+
else if (isIterable(ret)) {
|
|
482
|
+
finishCount++;
|
|
483
|
+
pumpToWeb(ret, stream, finish, pumpOptions);
|
|
484
|
+
}
|
|
485
|
+
else if (isTransformStream(ret)) {
|
|
486
|
+
finishCount++;
|
|
487
|
+
pumpToWeb(readWeb(ret.readable, destroys, finishOnlyHandleError), stream, finish, pumpOptions);
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
throw new ERR_INVALID_ARG_TYPE("val", [
|
|
491
|
+
"Readable",
|
|
492
|
+
"Iterable",
|
|
493
|
+
"AsyncIterable",
|
|
494
|
+
"ReadableStream",
|
|
495
|
+
"TransformStream",
|
|
496
|
+
], ret);
|
|
497
|
+
}
|
|
498
|
+
ret = stream;
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
ret = Duplex.from(stream);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (signal?.aborted || outerSignal?.aborted) {
|
|
505
|
+
nextTick(abort);
|
|
506
|
+
}
|
|
507
|
+
return ret;
|
|
508
|
+
}
|
|
509
|
+
export function pipe(src, dst, finish, finishOnlyHandleError, { end }) {
|
|
510
|
+
let ended = false;
|
|
511
|
+
dst.on("close", () => {
|
|
512
|
+
if (!ended) {
|
|
513
|
+
// Finish if the destination closes before the source has completed.
|
|
514
|
+
finishOnlyHandleError(new ERR_STREAM_PREMATURE_CLOSE());
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
// If end is true we already will have a listener to end dst.
|
|
518
|
+
src.pipe(dst, { end: false });
|
|
519
|
+
if (end) {
|
|
520
|
+
// Compat. Before node v10.12.0 stdio used to throw an error so
|
|
521
|
+
// pipe() did/does not end() stdio destinations.
|
|
522
|
+
// Now they allow it but "secretly" don't close the underlying fd.
|
|
523
|
+
function endFn() {
|
|
524
|
+
ended = true;
|
|
525
|
+
dst.end();
|
|
526
|
+
}
|
|
527
|
+
if (isReadableFinished(src)) {
|
|
528
|
+
// End the destination if the source has already ended.
|
|
529
|
+
nextTick(endFn);
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
src.once("end", endFn);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
finish();
|
|
537
|
+
}
|
|
538
|
+
eos(src, {
|
|
539
|
+
readable: true,
|
|
540
|
+
writable: false,
|
|
541
|
+
}, (err) => {
|
|
542
|
+
const rState = src._readableState;
|
|
543
|
+
if (err &&
|
|
544
|
+
err.code === "ERR_STREAM_PREMATURE_CLOSE" &&
|
|
545
|
+
rState &&
|
|
546
|
+
rState.ended &&
|
|
547
|
+
!rState.errored &&
|
|
548
|
+
!rState.errorEmitted) {
|
|
549
|
+
// Some readable streams will emit 'close' before 'end'. However, since
|
|
550
|
+
// this is on the readable side 'end' should still be emitted if the
|
|
551
|
+
// stream has been ended and no error emitted. This should be allowed in
|
|
552
|
+
// favor of backwards compatibility. Since the stream is piped to a
|
|
553
|
+
// destination this should not result in any observable difference.
|
|
554
|
+
// We don't need to check if this is a writable premature close since
|
|
555
|
+
// eos will only fail with premature close on the reading side for
|
|
556
|
+
// duplex streams.
|
|
557
|
+
src.once("end", finish).once("error", finish);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
finish(err);
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
return eos(dst, {
|
|
564
|
+
readable: false,
|
|
565
|
+
writable: true,
|
|
566
|
+
}, finish);
|
|
567
|
+
}
|