@eryx/stream/types Module

API Reference

Types

StreamThatCanClose

type StreamThatCanClose = { close: ((self: StreamThatCanClose) → ()), closeSync: ((self: StreamThatCanClose) → ()), closed: boolean? }
StreamThatCanClose:close()()

Closes this stream, setting closed to true

StreamThatCanClose:closeSync()()

Non-yielding version of close

closed: boolean?

A boolean indicating if this stream is already closed

StringStreamThatCanRead

type StringStreamThatCanRead = { readable: true, read: ((self: StringStreamThatCanRead, size: number?) → string), readSync: ((self: StringStreamThatCanRead, size: number?) → string) }
StringStreamThatCanRead:read(size: number?)string

Read data from the stream.

The formal Stream contract defines this as always returning a string.

Some implementations of streams may augment this function to return string? in non-blocking contexts.

StringStreamThatCanRead:readSync(size: number?)string

Non-yielding version of read

readable: true

Marks that this stream is readable

BufferStreamThatCanRead

type BufferStreamThatCanRead = { readable: true, readBuffer: ((self: BufferStreamThatCanRead, size: number?) → buffer), readBufferSync: ((self: BufferStreamThatCanRead, size: number?) → buffer) }
BufferStreamThatCanRead:readBuffer(size: number?)buffer

Read data from the stream, returning the data as a buffer. See read.

BufferStreamThatCanRead:readBufferSync(size: number?)buffer

Non-yielding version of readBuffer

readable: true

Marks that this stream is readable

StreamThatCanRead

Implements: StringStreamThatCanRead, BufferStreamThatCanRead

StringStreamThatCanWrite

type StringStreamThatCanWrite = { writable: true, write: ((self: StringStreamThatCanWrite, data: string) → number), writeSync: ((self: StringStreamThatCanWrite, data: string) → number) }
StringStreamThatCanWrite:write(data: string)number

Writes data to the stream

StringStreamThatCanWrite:writeSync(data: string)number

Non-yielding version of write

writable: true

Marks that this stream is writable

BufferStreamThatCanWrite

type BufferStreamThatCanWrite = { writable: true, write: ((self: BufferStreamThatCanWrite, data: buffer) → number), writeSync: ((self: BufferStreamThatCanWrite, data: buffer) → number) }
BufferStreamThatCanWrite:write(data: buffer)number

Writes data to the stream

BufferStreamThatCanWrite:writeSync(data: buffer)number

Non-yielding version of write

writable: true

Marks that this stream is writable

StreamThatCanWrite

Implements: StringStreamThatCanWrite, BufferStreamThatCanWrite

Whence

type Whence = "set" | "cur" | "end"

StreamThatCanSeek

type StreamThatCanSeek = { seek: ( self: StreamThatCanSeek, offset: number, whence: Whence? )number, tell: ((self: StreamThatCanSeek) → number) }
StreamThatCanSeek:seek(offset: number, whence: Whence?)number

Moves the file cursor.

StreamThatCanSeek:tell()number

Returns the current file cursor position.

StreamThatCanFlush

type StreamThatCanFlush = { flush: ((self: StreamThatCanFlush) → ()), flushSync: ((self: StreamThatCanFlush) → ()) }
StreamThatCanFlush:flush()()

Flushes buffered data

StreamThatCanFlush:flushSync()()

Flushes buffered data

ReadOnlyStream

Read-only stream contract.

read and readSync are intentionally generic and may return either string or buffer depending on the concrete stream source. Use readBuffer variants when you specifically need buffer.

type ReadOnlyStream = StreamThatCanClose & StreamThatCanRead & { writable: false }
Implements: StreamThatCanClose, StreamThatCanRead
writable: false

Indicates that this stream is read-only

WriteOnlyStream

Write-only stream contract.

write and writeSync accept string | buffer to support both text and binary producer code with one surface.

Implements: StreamThatCanClose, StreamThatCanWrite
readable: false

Indicates that this stream is write-only

ReadWriteStream

Duplex stream contract.

This is effectively ReadOnlyStream & WriteOnlyStream with explicit tags.

Implements: StreamThatCanClose, StreamThatCanRead, StreamThatCanWrite