/** * @since 1.0.0 */ import type { PlatformError } from "@effect/platform/Error" import type { SizeInput } from "@effect/platform/FileSystem" import type { Channel } from "effect/Channel" import type { Chunk } from "effect/Chunk" import type { Effect } from "effect/Effect" import type { LazyArg } from "effect/Function" import * as Stream from "effect/Stream" import type { Duplex, Readable } from "node:stream" import * as internal from "./internal/stream.js" /** * @category models * @since 1.0.0 */ export interface FromReadableOptions { /** Defaults to undefined, which lets Node.js decide the chunk size */ readonly chunkSize?: SizeInput /** Default to true, which means the stream will be closed when done */ readonly closeOnDone?: boolean | undefined } /** * @category model * @since 1.0.0 */ export interface FromWritableOptions { readonly endOnDone?: boolean readonly encoding?: BufferEncoding } /** * @category constructors * @since 1.0.0 */ export const fromReadable: >( evaluate: LazyArg, onError: (error: unknown) => E, options?: FromReadableOptions ) => Stream.Stream = internal.fromReadable /** * @category constructors * @since 1.0.0 */ export const fromReadableChannel: >( evaluate: LazyArg, onError: (error: unknown) => E, options?: FromReadableOptions | undefined ) => Channel, unknown, E> = internal.fromReadableChannel /** * @category constructors * @since 1.0.0 */ export const fromDuplex: ( evaluate: LazyArg, onError: (error: unknown) => E, options?: FromReadableOptions & FromWritableOptions ) => Channel, Chunk, IE | E, IE, void, unknown> = internal.fromDuplex /** * @category combinators * @since 1.0.0 */ export const pipeThroughDuplex: { /** * @category combinators * @since 1.0.0 */ ( duplex: LazyArg, onError: (error: unknown) => E2, options?: (FromReadableOptions & FromWritableOptions) | undefined ): (self: Stream.Stream) => Stream.Stream /** * @category combinators * @since 1.0.0 */ ( self: Stream.Stream, duplex: LazyArg, onError: (error: unknown) => E2, options?: (FromReadableOptions & FromWritableOptions) | undefined ): Stream.Stream } = internal.pipeThroughDuplex /** * @category combinators * @since 1.0.0 */ export const pipeThroughSimple: { /** * @category combinators * @since 1.0.0 */ (duplex: LazyArg): (self: Stream.Stream) => Stream.Stream /** * @category combinators * @since 1.0.0 */ (self: Stream.Stream, duplex: LazyArg): Stream.Stream } = internal.pipeThroughSimple /** * @since 1.0.0 * @category conversions */ export const toReadable: (stream: Stream.Stream) => Effect = internal.toReadable /** * @since 1.0.0 * @category conversions */ export const toReadableNever: (stream: Stream.Stream) => Readable = internal.toReadableNever /** * @since 1.0.0 * @category conversions */ export const toString: ( readable: LazyArg, options: { readonly onFailure: (error: unknown) => E readonly encoding?: BufferEncoding | undefined readonly maxBytes?: SizeInput | undefined } ) => Effect = internal.toString /** * @since 1.0.0 * @category conversions */ export const toUint8Array: ( readable: LazyArg, options: { readonly onFailure: (error: unknown) => E; readonly maxBytes?: SizeInput | undefined } ) => Effect = internal.toUint8Array /** * @since 1.0.0 * @category stdio */ export const stdin: Stream.Stream = internal.fromReadable(() => process.stdin, (err) => err, { closeOnDone: false }).pipe(Stream.orDie) /** * @since 1.0.0 * @category stdio */ export const stdout: Stream.Stream = internal.fromReadable(() => process.stdout, (err) => err, { closeOnDone: false }).pipe(Stream.orDie) /** * @since 1.0.0 * @category stdio */ export const stderr: Stream.Stream = internal.fromReadable(() => process.stderr, (err) => err, { closeOnDone: false }).pipe(Stream.orDie)