NodeStream.ts
NodeStream.ts overview
Section titled “NodeStream.ts overview”Adapters between Node streams and Effect streams, channels, and readables.
This module is the stream boundary for Node APIs. It wraps Readable and
Duplex values as Effect Streams and Channels, pipes Effect streams
through Node duplex streams, exposes an Effect Stream back to Node as a
Readable, and collects readable payloads into strings, array buffers, or
Uint8Arrays with optional byte limits.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”combinators
Section titled “combinators”pipeThroughDuplex
Section titled “pipeThroughDuplex”Pipes an Effect Stream through a Node Duplex, writing the stream’s
chunks to the duplex and emitting chunks read back from it.
Signature
declare const pipeThroughDuplex: { <B = Uint8Array<ArrayBufferLike>, E2 = Cause.UnknownError>(options: { readonly evaluate: LazyArg<Duplex> readonly onError?: (error: unknown) => E2 readonly chunkSize?: number | undefined readonly bufferSize?: number | undefined readonly endOnDone?: boolean | undefined readonly encoding?: BufferEncoding | undefined }): <R, E, A>(self: Stream.Stream<A, E, R>) => Stream.Stream<B, E2 | E, R> <R, E, A, B = Uint8Array<ArrayBufferLike>, E2 = Cause.UnknownError>( self: Stream.Stream<A, E, R>, options: { readonly evaluate: LazyArg<Duplex> readonly onError?: (error: unknown) => E2 readonly chunkSize?: number | undefined readonly bufferSize?: number | undefined readonly endOnDone?: boolean | undefined readonly encoding?: BufferEncoding | undefined } ): Stream.Stream<B, E | E2, R>}Since v4.0.0
pipeThroughSimple
Section titled “pipeThroughSimple”Pipes a stream of strings or bytes through a Node Duplex using default
options and Cause.UnknownError for stream failures.
Signature
declare const pipeThroughSimple: { ( duplex: LazyArg<Duplex> ): <R, E>(self: Stream.Stream<string | Uint8Array, E, R>) => Stream.Stream<Uint8Array, E | Cause.UnknownError, R> <R, E>( self: Stream.Stream<string | Uint8Array, E, R>, duplex: LazyArg<Duplex> ): Stream.Stream<Uint8Array, Cause.UnknownError | E, R>}Since v4.0.0
constructors
Section titled “constructors”fromDuplex
Section titled “fromDuplex”Creates a Channel over a Node Duplex, writing upstream chunks with
backpressure while emitting chunks read from the duplex and optionally ending
the writable side when upstream completes.
Signature
declare const fromDuplex: < IE, I = Uint8Array<ArrayBufferLike>, O = Uint8Array<ArrayBufferLike>, E = Cause.UnknownError>(options: { readonly evaluate: LazyArg<Duplex> readonly onError?: (error: unknown) => E readonly chunkSize?: number | undefined readonly bufferSize?: number | undefined readonly endOnDone?: boolean | undefined readonly encoding?: BufferEncoding | undefined}) => Channel.Channel<Arr.NonEmptyReadonlyArray<O>, IE | E, void, Arr.NonEmptyReadonlyArray<I>, IE>Since v4.0.0
fromReadable
Section titled “fromReadable”Converts a Node readable stream into an Effect Stream, reading chunks with
an optional chunk size, mapping stream errors with onError, and destroying
the readable on completion unless closeOnDone is false.
Signature
declare const fromReadable: <A = Uint8Array<ArrayBufferLike>, E = Cause.UnknownError>(options: { readonly evaluate: LazyArg<Readable | NodeJS.ReadableStream> readonly onError?: (error: unknown) => E readonly chunkSize?: number | undefined readonly bufferSize?: number | undefined readonly closeOnDone?: boolean | undefined}) => Stream.Stream<A, E>Since v4.0.0
fromReadableChannel
Section titled “fromReadableChannel”Creates a Channel that pulls chunks from a Node readable stream, mapping
errors with onError and destroying the readable on completion unless
closeOnDone is false.
Signature
declare const fromReadableChannel: <A = Uint8Array<ArrayBufferLike>, E = Cause.UnknownError>(options: { readonly evaluate: LazyArg<Readable | NodeJS.ReadableStream> readonly onError?: (error: unknown) => E readonly chunkSize?: number | undefined readonly closeOnDone?: boolean | undefined}) => Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E>Since v4.0.0
converting
Section titled “converting”toArrayBuffer
Section titled “toArrayBuffer”Consumes a Node readable stream into an ArrayBuffer, failing through
onError on stream errors or when maxBytes is exceeded and destroying the
stream on interruption or failure.
Signature
declare const toArrayBuffer: <E = Cause.UnknownError>( readable: LazyArg<Readable | NodeJS.ReadableStream>, options?: { readonly onError?: (error: unknown) => E; readonly maxBytes?: SizeInput | undefined }) => Effect.Effect<ArrayBuffer, E>Since v4.0.0
toReadable
Section titled “toReadable”Converts an Effect Stream into a Node Readable, using the caller’s
Effect context to run the stream and destroying the readable if the stream
fails.
Signature
declare const toReadable: <E, R>(stream: Stream.Stream<string | Uint8Array, E, R>) => Effect.Effect<Readable, never, R>Since v4.0.0
toReadableNever
Section titled “toReadableNever”Converts a service-free Effect Stream into a Node Readable using an
empty Effect context.
Signature
declare const toReadableNever: <E>(stream: Stream.Stream<string | Uint8Array, E, never>) => ReadableSince v4.0.0
toString
Section titled “toString”Consumes a Node readable stream into a string using the selected encoding,
failing through onError on stream errors or when maxBytes is exceeded
and destroying the stream on interruption or failure.
Signature
declare const toString: <E = Cause.UnknownError>( readable: LazyArg<Readable | NodeJS.ReadableStream>, options?: { readonly onError?: (error: unknown) => E readonly encoding?: BufferEncoding | undefined readonly maxBytes?: SizeInput | undefined }) => Effect.Effect<string, E>Since v4.0.0
toUint8Array
Section titled “toUint8Array”Consumes a Node readable stream into a Uint8Array, using the same error
mapping and maxBytes handling as toArrayBuffer.
Signature
declare const toUint8Array: <E = Cause.UnknownError>( readable: LazyArg<Readable | NodeJS.ReadableStream>, options?: { readonly onError?: (error: unknown) => E; readonly maxBytes?: SizeInput | undefined }) => Effect.Effect<Uint8Array, E>Since v4.0.0