core/io
io
Types
26Closer
Closer :: StreamSourceError
Error :: enum i32 {
// No Error
None = 0,
// EOF is the error returned by `read` when no more input is available
EOF = 1,
// Unexpected_EOF means that EOF was encountered in the middle of reading a fixed-sized block of data
Unexpected_EOF = 2,
// Short_Write means that a write accepted fewer bytes than requested but failed to return an explicit error
Short_Write = 3,
// Invalid_Write means that a write returned an impossible count
Invalid_Write = 4,
// Short_Buffer means that a read/write required a longer buffer than was provided
Short_Buffer = 5,
// No_Progress is returned by some implementations of `io.Reader` when many calls
// to `read` have failed to return any data or error.
// This is usually a sign of a broken `io.Reader` implementation
No_Progress = 6,
// Invalid whence argument
Invalid_Whence = 7,
// Invalid offset
Invalid_Offset = 8,
// Invalid "unread" operation
Invalid_Unread = 9,
Negative_Read = 10,
Negative_Write = 11,
Negative_Count = 12,
Buffer_Full = 13,
// Unknown means that an error has occurred but cannot be categorized
Unknown = 14,
// Indicates that an attempt to retrieve a Stream's size was made, but the
// stream doesn't have a size.
No_Size = 15,
Permission_Denied = 16,
// Stream cannot be used since it has been Closed
Closed = 17,
// Unsupported is returned when a procedure has not been implemented for an io.Stream
Unsupported = -1,
Empty = Unsupported,
}SourceFlusher
Flusher :: StreamSourceLimited_Reader
Limited_Reader :: struct {
r: Reader,
n: i64,
}SourceA 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.
Multi_Reader
Multi_Reader :: struct {
readers: [dynamic]Reader,
}SourceMulti_Writer
Multi_Writer :: struct {
writers: [dynamic]Writer,
}SourceRead_Closer
Read_Closer :: StreamSourceRead_Write_Closer
Read_Write_Closer :: StreamSourceRead_Write_Seeker
Read_Write_Seeker :: StreamSourceRead_Writer
Read_Writer :: StreamSourceReader
Reader :: StreamSourceReader_At
Reader_At :: StreamSourceSection_Reader
Section_Reader :: struct {
r: Reader_At,
base: i64,
off: i64,
limit: i64,
}SourceSection_Reader implements read, seek, and read_at on a section of an underlying Reader_At
Seek_From
Seek_From :: enum int {
Start = 0, // seek relative to the origin of the file
Current = 1, // seek relative to the current offset
End = 2, // seek relative to the end
}SourceSeek whence values
Seeker
Seeker :: StreamSourceStream
Stream :: struct {
procedure: Stream_Proc,
data: rawptr,
}SourceStream_Mode
Stream_Mode :: enum int {
Close = 0,
Flush = 1,
Read = 2,
Read_At = 3,
Write = 4,
Write_At = 5,
Seek = 6,
Size = 7,
Destroy = 8,
Query = 9, // query what modes are available
}SourceStream_Mode_Set
Stream_Mode_Set :: bit_set[Stream_Mode; i64]SourceStream_Proc
Stream_Proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []u8, offset: i64, whence: Seek_From) -> (n: i64, err: Error)SourceTee_Reader
Tee_Reader :: struct {
r: Reader,
w: Writer,
}SourceWrite_Closer
Write_Closer :: StreamSourceWrite_Flush_Closer
Write_Flush_Closer :: StreamSourceWrite_Flusher
Write_Flusher :: StreamSourceWrite_Seeker
Write_Seeker :: StreamSourceWriter
Writer :: StreamSourceWriter_At
Writer_At :: StreamSourceProcedures
73_i64_err
_i64_err :: proc(n: int, err: Error) -> (Error, i64)Source_multi_reader_proc
_multi_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []u8, offset: i64, whence: Seek_From) -> (n: i64, err: Error)Source_multi_writer_proc
_multi_writer_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []u8, offset: i64, whence: Seek_From) -> (n: i64, err: Error)Sourceclose
close :: proc(s: Closer) -> (err: Error)SourceThe behaviour of close after the first call is stream implementation defined. Different streams may document their own behaviour.
copy
copy :: proc(dst: Writer, src: Reader) -> (written: i64, err: Error)Sourcecopy 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
copy_buffer :: proc(dst: Writer, src: Reader, buf: []u8) -> (written: i64, err: Error)Sourcecopy_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
copy_n :: proc(dst: Writer, src: Reader, n: i64) -> (written: i64, err: Error)Sourcecopy_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
destroy
destroy :: proc(s: Stream) -> (err: Error)Sourceflush
flush :: proc(s: Flusher) -> (err: Error)Sourcelimited_reader_init
limited_reader_init :: proc(l: ^Limited_Reader, r: Reader, n: i64) -> (Reader)Sourcelimited_reader_to_reader
limited_reader_to_reader :: proc(l: ^Limited_Reader) -> (r: Reader)Sourcemulti_reader_destroy
multi_reader_destroy :: proc(mr: ^Multi_Reader)Sourcemulti_reader_init
multi_reader_init :: proc(mr: ^Multi_Reader, readers, allocator: mem.Allocator = context.allocator) -> (r: Reader)Sourcemulti_writer_destroy
multi_writer_destroy :: proc(mw: ^Multi_Writer)Sourcemulti_writer_init
multi_writer_init :: proc(mw: ^Multi_Writer, writers, allocator: mem.Allocator = context.allocator) -> (out: Writer)Sourcen_wrapper
n_wrapper :: proc(n: int, err: Error, bytes_processed: ^int) -> (Error)Sourcequery
query :: proc(s: Stream) -> (set: Stream_Mode_Set)Sourcequery_utility
query_utility :: proc(set: Stream_Mode_Set) -> (n: i64, err: Error)Sourceread
read :: proc(s: Reader, p: []u8, n_read: ^int) -> (n: int, err: Error)Sourceread 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
read_at :: proc(r: Reader_At, p: []u8, offset: i64, n_read: ^int) -> (n: int, err: Error)Sourceread_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
read_at_least :: proc(r: Reader, buf: []u8, min: int) -> (n: int, err: Error)Sourceread_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_byte
read_byte :: proc(r: Reader, n_read: ^int) -> (b: u8, err: Error)Sourceread_byte reads and returns the next byte from r.
read_full
read_full :: proc(r: Reader, buf: []u8) -> (n: int, err: Error)Sourceread_full expected exactly len(buf) bytes from r into buf.
read_ptr
read_ptr :: proc(r: Reader, p: rawptr, byte_size: int, n_read: ^int) -> (n: int, err: Error)Sourceread_ptr_at
read_ptr_at :: proc(r: Reader_At, p: rawptr, byte_size: int, offset: i64, n_read: ^int) -> (n: int, err: Error)Sourceread_rune
read_rune :: proc(br: Reader, n_read: ^int) -> (ch: rune, size: int, err: Error)Sourceread_rune reads a single UTF-8 encoded Unicode codepoint and returns the rune and its size in bytes.
read_slice
read_slice :: proc(r: Reader, slice: S, n_read: ^int) -> (n: int, err: Error)Sourcesection_reader_init
section_reader_init :: proc(s: ^Section_Reader, r: Reader_At, off: i64, n: i64) -> (Reader)Sourcesection_reader_to_stream
section_reader_to_stream :: proc(s: ^Section_Reader) -> (out: Stream)Sourceseek
seek :: proc(s: Seeker, offset: i64, whence: Seek_From) -> (n: i64, err: Error)Sourceseek 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
size :: proc(s: Stream) -> (n: i64, err: Error)Sourcesize returns the size of the stream. If the stream does not support querying its size, 0 will be returned.
tee_reader_init
tee_reader_init :: proc(t: ^Tee_Reader, r: Reader, w: Writer, allocator: mem.Allocator = context.allocator) -> (Reader)Sourcetee_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
tee_reader_to_reader
tee_reader_to_reader :: proc(t: ^Tee_Reader) -> (r: Reader)Sourceto_closer
to_closer :: proc(s: Stream) -> (c: Closer, ok: bool)Sourceto_flusher
to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool)Sourceto_read_closer
to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool)Sourceto_read_write_closer
to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool)Sourceto_read_write_seeker
to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool)Sourceto_read_writer
to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool)Sourceto_reader
to_reader :: proc(s: Stream) -> (r: Reader, ok: bool)Sourceto_reader_at
to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool)Sourceto_seeker
to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool)Sourceto_write_closer
to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool)Sourceto_write_flush_closer
to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool)Sourceto_write_flusher
to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool)Sourceto_write_seeker
to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool)Sourceto_writer
to_writer :: proc(s: Stream) -> (w: Writer, ok: bool)Sourceto_writer_at
to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool)Sourcewrite
write :: proc(s: Writer, p: []u8, n_written: ^int) -> (n: int, err: Error)Sourcewrite writes up to len(p) bytes into p. It returns the number of bytes written and any error if occurred.
write_at
write_at :: proc(w: Writer_At, p: []u8, offset: i64, n_written: ^int) -> (n: int, err: Error)Sourcewrite_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
write_at_least :: proc(w: Writer, buf: []u8, min: int) -> (n: int, err: Error)Sourcewrite_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_byte
write_byte :: proc(w: Writer, c: u8, n_written: ^int) -> (Error)Sourcewrite_encoded_rune
write_encoded_rune :: proc(w: Writer, r: rune, write_quote: untyped boolean = true, n_written: ^int) -> (n: int, err: Error)Sourcewrite_escaped_rune
write_escaped_rune :: proc(
w: Writer,
r: rune,
quote: u8,
html_safe: untyped boolean = false,
n_written: ^int,
for_json: untyped boolean = false,
) -> (n: int, err: Error)Sourcewrite_f16
write_f16 :: proc(w: Writer, val: f16, n_written: ^int) -> (n: int, err: Error)Sourcewrite_f32
write_f32 :: proc(w: Writer, val: f32, n_written: ^int) -> (n: int, err: Error)Sourcewrite_f64
write_f64 :: proc(w: Writer, val: f64, n_written: ^int) -> (n: int, err: Error)Sourcewrite_full
write_full :: proc(w: Writer, buf: []u8) -> (n: int, err: Error)Sourcewrite_full writes until the entire contents of buf has been written or an error occurs.
write_i128
write_i128 :: proc(w: Writer, i: i128, base: int, n_written: ^int) -> (n: int, err: Error)Sourcewrite_i64
write_i64 :: proc(w: Writer, i: i64, base: int, n_written: ^int) -> (n: int, err: Error)Sourcewrite_int
write_int :: proc(w: Writer, i: int, base: int, n_written: ^int) -> (n: int, err: Error)Sourcewrite_ptr
write_ptr :: proc(w: Writer, p: rawptr, byte_size: int, n_written: ^int) -> (n: int, err: Error)Sourcewrite_ptr_at
write_ptr_at :: proc(w: Writer_At, p: rawptr, byte_size: int, offset: i64, n_written: ^int) -> (n: int, err: Error)Sourcewrite_quoted_rune
write_quoted_rune :: proc(w: Writer, r: rune) -> (n: int)Sourcewriter append a quoted rune into the byte buffer, return the written size
write_quoted_string
write_quoted_string :: proc()Sourcewrite_quoted_string16
write_quoted_string16 :: proc()Sourcewrite_rune
write_rune :: proc(s: Writer, r: rune, n_written: ^int) -> (size: int, err: Error)Sourcewrite_rune writes a UTF-8 encoded rune to w.
write_slice
write_slice :: proc(w: Writer, slice: S, n_written: ^int) -> (n: int, err: Error)Sourcewrite_string
write_string :: proc(s: Writer, str: string, n_written: ^int) -> (n: int, err: Error)Sourcewrite_string writes the contents of the string s to w.
write_string16
write_string16 :: proc(s: Writer, str: string16, n_written: ^int) -> (n: int, err: Error)Sourcewrite_string16 writes the contents of the string16 s to w reencoded as utf-8
write_u128
write_u128 :: proc(w: Writer, i: u128, base: int, n_written: ^int) -> (n: int, err: Error)Sourcewrite_u64
write_u64 :: proc(w: Writer, i: u64, base: int, n_written: ^int) -> (n: int, err: Error)Sourcewrite_uint
write_uint :: proc(w: Writer, i: uint, base: int, n_written: ^int) -> (n: int, err: Error)Source