Class Stream<T>
Source: stream.ts
A communication channel for process I/O, supporting event-based data transmission, signaling, and piping between streams.
Extends
Extended by
Type Parameters
T
T = string
Implements
InputStream<T>OutputStream<T>
Constructors
Constructor
new Stream<
T>():Stream<T>
Returns
Stream<T>
Inherited from
EventEmitter<StreamEvents<T>>.constructor
Properties
DATA_EVENT
readonlystaticDATA_EVENT:"data"="data"
END_EVENT
readonlystaticEND_EVENT:"end"="end"
SIGNAL_EVENT
readonlystaticSIGNAL_EVENT:"signal"="signal"
ERROR_EVENT
readonlystaticERROR_EVENT:"error"="error"
INTERRUPTED
readonlystaticINTERRUPTED:"interrupted"="interrupted"
CLOSED
readonlystaticCLOSED:"closed"="closed"
Methods
readLines()
staticreadLines(stream:InputStream):AsyncGenerator<Result<string,StreamError>>
Iterates over a readable string stream and yields each line.
Parameters
stream
Returns
AsyncGenerator<Result<string, StreamError>>
end()
end():
this
Closes the stream (EOF). Subsequent calls to write will be rejected.
Returns
this
signal()
signal(
signal:StreamSignal):this
Emits a control signal. Standard termination signals will automatically close the stream.
Parameters
signal
Returns
this
write()
write(
data:T):Promise<Result<void,StreamError>>
Broadcasts data to all listeners if the stream is open.
Parameters
data
T
Returns
Promise<Result<void, StreamError>>
Implementation of
read()
read():
Promise<Result<T|null,StreamError>>
Resolves with the next available chunk, or null if the stream is closed (EOF).
Returns
Promise<Result<T | null, StreamError>>
Implementation of
pipe()
pipe(
destination:Stream<T>,propagateEnd?:boolean):Stream<T>
Forwards data, end events, and signals from this stream to another.
Parameters
destination
Stream<T>
The stream that will receive the forwarded data.
propagateEnd?
boolean = true
Returns
Stream<T>
The destination stream to allow for chainable piping.
wait()
Call Signature
wait():
Promise<void>
Returns a promise that resolves when the stream is stopped.
Returns
Promise<void>
Call Signature
wait<
U>(value:U):Promise<U>
Returns a promise that resolves when the stream is stopped.
Type Parameters
U
U
Parameters
value
U
Value to return when the promise resolves.
Returns
Promise<U>
on()
on<
K>(event:K,listener:Listener<StreamEvents<T>,K>):Listener<StreamEvents<T>,K>
Starts listening to an event.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to listen to.
listener
Listener<StreamEvents<T>, K>
The function to call when the event is emitted.
Returns
Listener<StreamEvents<T>, K>
The listener.
Inherited from
EventEmitter.on
once()
once<
K>(event:K,listener:Listener<StreamEvents<T>,K>):Listener<StreamEvents<T>,K>
Registers an event listener that is automatically removed when called.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to listen to.
listener
Listener<StreamEvents<T>, K>
The function to call once the event is emitted.
Returns
Listener<StreamEvents<T>, K>
The wrapped listener.
Inherited from
EventEmitter.once
off()
off<
K>(event:K,listener:Listener<StreamEvents<T>,K>):void
Removes an event listener.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to remove the listener from.
listener
Listener<StreamEvents<T>, K>
The listener to remove.
Returns
void
Inherited from
EventEmitter.off
emit()
emit<
K>(event:K, ...args:StreamEvents<T>[K]):void
Emits an event to all its listeners.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to emit.
args
...StreamEvents<T>[K]
The arguments to pass to the listeners.
Returns
void
Inherited from
EventEmitter.emit
emitAsync()
emitAsync<
K>(event:K, ...args:StreamEvents<T>[K]):Promise<void>
Emits an event and waits for all listeners to resolve.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to emit.
args
...StreamEvents<T>[K]
The arguments to pass to the listeners.
Returns
Promise<void>
Inherited from
EventEmitter.emitAsync