Basic interfaces for generic data stream primitives. The purpose of this package is wrap existing data structures and their operations into an abstracted stream interface.

Collection Info

View Source
Collection
core
Path
io
Entries
96

Source Files

Types

26

Limited_Reader #

Source
Limited_Reader :: Limited_Reader

A Limited_Reader reads from r but limits the amount of data returned to just n bytes. Each call to read updates n to reflect the new amount remaining. read returns EOF when n <= 0 or when the underlying r returns EOF.

Section_Reader #

Source
Section_Reader :: Section_Reader

Section_Reader implements read, seek, and read_at on a section of an underlying Reader_At

Procedures

70

close #

Source
close :: proc(s: Stream) -> (err: Error) {…}

The behaviour of close after the first call is stream implementation defined. Different streams may document their own behaviour.

copy #

Source
copy :: proc(dst: Stream, src: Stream) -> (written: i64, err: Error) {…}

copy copies from src to dst till either EOF is reached on src or an error occurs It returns the number of bytes copied and the first error that occurred whilst copying, if any.

copy_buffer #

Source
copy_buffer :: proc(dst: Stream, src: Stream, buf: []u8) -> (written: i64, err: Error) {…}

copy_buffer is the same as copy except that it stages through the provided buffer (if one is required) rather than allocating a temporary one on the stack through `intrinsics.alloca` If buf is `nil`, it is allocate through `intrinsics.alloca`; otherwise if it has zero length, it will panic

copy_n #

Source
copy_n :: proc(dst: Stream, src: Stream, n: i64) -> (written: i64, err: Error) {…}

copy_n copies n bytes (or till an error) from src to dst. It returns the number of bytes copied and the first error that occurred whilst copying, if any. On return, written == n if and only if (⟺) err == nil

read #

Source
read :: proc(s: Stream, p: []u8, n_read: ^int = nil) -> (n: int, err: Error) {…}

read reads up to len(p) bytes into p. It returns the number of bytes read and any error if occurred. When read encounters an .EOF or error after successfully reading n > 0 bytes, it returns the number of bytes read along with the error.

read_at #

Source
read_at :: proc(r: Stream, p: []u8, offset: i64, n_read: ^int = nil) -> (n: int, err: Error) {…}

read_at reads len(p) bytes into p starting with the provided offset in the underlying Reader_At stream r. It returns the number of bytes read and any error if occurred. When read_at returns n < len(p), it returns a non-nil Error explaining why. If n == len(p), err may be either nil or .EOF

read_at_least #

Source
read_at_least :: proc(r: Stream, buf: []u8, min: int) -> (n: int, err: Error) {…}

read_at_least reads from r into buf until it has read at least min bytes. It returns the number of bytes copied and an error if fewer bytes were read. `.EOF` is only returned if no bytes were read. `.Unexpected_EOF` is returned when an `.EOF ` is returned by the passed Reader after reading fewer than min bytes. If len(buf) is less than min, `.Short_Buffer` is returned.

read_rune #

Source
read_rune :: proc(br: Stream, n_read: ^int = nil) -> (ch: rune, size: int, err: Error) {…}

read_rune reads a single UTF-8 encoded Unicode codepoint and returns the rune and its size in bytes.

seek #

Source
seek :: proc(s: Stream, offset: i64, whence: Seek_From) -> (n: i64, err: Error) {…}

seek sets the offset of the next read or write to offset. .Start means seek relative to the origin of the file. .Current means seek relative to the current offset. .End means seek relative to the end. seek returns the new offset to the start of the file/stream, and any error if occurred.

size #

Source
size :: proc(s: Stream) -> (n: i64, err: Error) {…}

size returns the size of the stream. If the stream does not support querying its size, 0 will be returned.

tee_reader_init #

Source
tee_reader_init :: proc(t: ^Tee_Reader, r: Stream, w: Stream, allocator := context.allocator) -> Stream {…}

tee_reader_init returns a Reader that writes to 'w' what it reads from 'r' All reads from 'r' performed through it are matched with a corresponding write to 'w' There is no internal buffering done The write must complete before th read completes Any error encountered whilst writing is reported as a 'read' error tee_reader_init must call io.destroy when done with

write #

Source
write :: proc(s: Stream, p: []u8, n_written: ^int = nil) -> (n: int, err: Error) {…}

write writes up to len(p) bytes into p. It returns the number of bytes written and any error if occurred.

write_at #

Source
write_at :: proc(w: Stream, p: []u8, offset: i64, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_at writes len(p) bytes into p starting with the provided offset in the underlying Writer_At stream w. It returns the number of bytes written and any error if occurred. If write_at is writing to a Writer_At which has a seek offset, then write_at should not affect the underlying seek offset.

write_at_least #

Source
write_at_least :: proc(w: Stream, buf: []u8, min: int) -> (n: int, err: Error) {…}

write_at_least writes at least `buf[:min]` to the writer and returns the amount written. If an error occurs before writing everything it is returned.

write_full #

Source
write_full :: proc(w: Stream, buf: []u8) -> (n: int, err: Error) {…}

write_full writes until the entire contents of `buf` has been written or an error occurs.

write_quoted_rune #

Source
write_quoted_rune :: proc(w: Stream, r: rune) -> (n: int) {…}

writer append a quoted rune into the byte buffer, return the written size

write_string16 #

Source
write_string16 :: proc(s: Stream, str: string16, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_string16 writes the contents of the string16 s to w reencoded as utf-8