/io
Buffered and standard stream I/O (Buf-Reader, Buf-Writer, Stdin, Stdout, Stderr, read-line, write-line, flush, and ask).
Functions & symbols#
*err*#
Active standard error sink used by diagnostics and tracing, rebindable via `let-ds`.
Any(use {*err* Buffer} /io)
(let err (Buffer))
(let-ds [*err* err] (write-line *err* "warn"))*in*#
Active standard input source used by `(tty/ask)` and rebindable via `let-ds` to any `Read` / `Read-Text` value.
Any(use {*in* Buffer} /io)
(let-ds [*in* (Buffer "hello\n")] (read-line *in*))*out*#
Active standard output sink used by `say`, `echo`, `writeln`, `dump`, and `(tty/ask)`, rebindable via `let-ds` to any `Write` / `Write-Text` value.
Any(use {*out* Buffer} /io)
(let buf (Buffer))
(let-ds [*out* buf] (say "hi"))Buf-Reader#
Wraps a `Read` source with an internal read buffer implementing `Read` and `Read-Text`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
source | Any | required | Underlying `Read` source |
buffer-size | Int | required | Optional internal chunk size in bytes |
AnyBuf-Writer#
Wraps a `Write` sink with an internal write buffer implementing `Write`, `Write-Text`, and `Flush`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
sink | Any | required | Underlying `Write` sink |
buffer-size | Int | required | Optional internal flush threshold in bytes |
AnyBuffer#
Constructs an in-memory growable byte queue implementing `Read`, `Read-Text`, `Write`, `Write-Text`, `Flush`, and `Countable`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
init-or-capacity | String | Slab | Int | required | Optional initial String/Slab contents or preallocated byte capacity |
Any(let buf (Buffer "line1\nline2"))
(read-line buf)Tee-Writer#
Constructs a multi-sink fan-out writer implementing `Write`, `Write-Text`, and `Flush`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
sinks | Any | required | Zero or more downstream `Write` / `Write-Text` sinks |
Any(let tee (Tee-Writer buf1 buf2))
(write-line tee "hello")flush#
Flushes all buffered output bytes in `writer`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
writer | Buf-Writer | File | Buffer | required | Writable stream |
Any(io/flush w)read#
Reads bytes from `reader` into `buf` and returns byte count read.
| Parameter | Type | Optional | Description |
|---|---|---|---|
reader | Buf-Reader | File | Buffer | required | Readable stream implementing Read |
buf | Slab | required | Mutable byte Slab |
Any(io/read r slab)read-all#
Reads all remaining bytes from `reader` until EOF into a `Slab`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
reader | Buf-Reader | File | Buffer | required | Readable stream |
Any(io/read-all r)read-byte#
Reads a single byte (`U8`) from `reader`, returning `()` at EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
reader | Buf-Reader | File | Buffer | required | Readable stream |
Any(io/read-byte r)read-char#
Reads a single UTF-8 `Char` from `reader`, returning `()` at EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
reader | Buf-Reader | File | required | Readable text stream |
Any(io/read-char r)read-line#
Reads the next line of UTF-8 text from `reader`, returning `()` at EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
reader | Buf-Reader | File | required | Readable text stream |
Any(io/read-line r)read-string#
Reads all remaining UTF-8 text from `reader` until EOF.
| Parameter | Type | Optional | Description |
|---|---|---|---|
reader | Buf-Reader | File | required | Readable text stream |
Any(io/read-string r)with-output-to-string#
Captures everything written to `*out*` during `(func)` and returns it as a `String`, restoring `*out*` on exit.
| Parameter | Type | Optional | Description |
|---|---|---|---|
func | Func | required | Zero-argument function executed while `*out*` is bound to a fresh `Buffer` |
Any(with-output-to-string (Func () (say "captured")))write#
Writes bytes or string data to `writer` and returns bytes written.
| Parameter | Type | Optional | Description |
|---|---|---|---|
writer | Buf-Writer | File | Buffer | required | Writable stream |
data | String | Slab | required | Bytes or text to write |
Any(io/write w "data")write-byte#
Writes one byte to `writer`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
writer | Buf-Writer | File | Buffer | required | Writable stream |
byte | U8 | Int | required | Single byte |
Any(io/write-byte w 10u8)write-line#
Writes `line` followed by a newline to `writer`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
writer | Buf-Writer | File | required | Writable text stream |
line | String | required | Line string |
Any(io/write-line w "hello")write-string#
Writes `str` directly to `writer` without adding a newline.
| Parameter | Type | Optional | Description |
|---|---|---|---|
writer | Buf-Writer | File | required | Writable text stream |
str | String | required | UTF-8 string |
Any(io/write-string w "part")