IO
Module io
import io
| Module | io |
| Source | io/capabilities.zirr, io/module-docs.zirr, io/reader-writer.zirr |
Bytes in, bytes out — described as attributes, not classes.
io describes streams rather than implementing them. Reader and Writer are attributes, so any type becomes a stream by carrying one — a file, a socket, or a buffer you wrote yourself. Functions that move bytes take @io.Reader or @io.Writer and never care which.
ReadStream and WriteStream are simply the ones the host hands out; os.os.stdout returns a WriteStream, and an open fs.File carries both attributes at once.
The Has… attributes are the other half: a program declares that its environment provides a writer, and a test passes one that collects into memory instead of reaching for standard output.
Contents
- Data —
ReadStream,WriteStream - Attributes —
HasErrorWriter,HasStandardReader,HasStandardWriter,Reader,Writer
Data
ReadStream
`io/reader-writer.zirr:18`
data ReadStream {
readFrom: fn(Int) -> Binary
}
A readable stream backed by the host, such as standard input or an open file.
Any type can be a reader by carrying @Reader; this is simply the one the host hands out.
Fields
| Field | Description |
|---|---|
readFrom |
WriteStream
`io/reader-writer.zirr:24`
data WriteStream {
writeTo: fn(Binary) -> Int
}
A writable stream backed by the host, such as standard output or an open file.
Fields
| Field | Description |
|---|---|
writeTo |
Attributes
HasErrorWriter
`io/capabilities.zirr:11`
attr HasErrorWriter {
writer(self) -> @Writer
}
Provides a standard error writer.
In production, this usually points to os.stderr.
Fields
| Field | Description |
|---|---|
writer |
HasStandardReader
`io/capabilities.zirr:17`
attr HasStandardReader {
reader(self) -> @Reader
}
Provides a standard input writer.
In production, this usually points to os.stdin.
Fields
| Field | Description |
|---|---|
reader |
HasStandardWriter
`io/capabilities.zirr:5`
attr HasStandardWriter {
writer(self) -> @Writer
}
Provides a standard out writer.
In production, this usually points to os.stdout.
Fields
| Field | Description |
|---|---|
writer |
Reader
`io/reader-writer.zirr:4`
attr Reader {
read(self: @Reader, length: Int) -> Binary
}
Marks a type as a readable stream of bytes.
Fields
| Field | Description |
|---|---|
read |
Reads up to the given number of bytes. An empty result means the stream is exhausted. |
Writer
`io/reader-writer.zirr:10`
attr Writer {
write(self: @Writer, buf: Binary) -> Int
}
Marks a type as a writable stream of bytes.
Fields
| Field | Description |
|---|---|
write |
Writes the given buffer and returns the number of bytes written. |