package core:io

Overview

package io provides 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.

Index

Constants (0)

This section is empty.

Variables (0)

This section is empty.

Procedures (68)
Procedure Groups (0)

This section is empty.

Types

Close_Proc ¶

Close_Proc :: proc "odin" (s: Stream) -> Error

Closer ¶

Closer :: struct {
	stream: Stream,
}

Destroy_Proc ¶

Destroy_Proc :: proc "odin" (s: Stream) -> Error

Error ¶

Error :: enum i32 {
	// No Error
	None           = 0, 
	// EOF is the error returned by `read` when no more input is available
	EOF, 
	// Unexpected_EOF means that EOF was encountered in the middle of reading a fixed-sized block of data
	Unexpected_EOF, 
	// Short_Write means that a write accepted fewer bytes than requested but failed to return an explicit error
	Short_Write, 
	// Invalid_Write means that a write returned an impossible count
	Invalid_Write, 
	// Short_Buffer means that a read required a longer buffer than was provided
	Short_Buffer, 
	// 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 signed of a broken `io.Reader` implementation
	No_Progress, 
	Invalid_Whence, 
	Invalid_Offset, 
	Invalid_Unread, 
	Negative_Read, 
	Negative_Write, 
	Negative_Count, 
	Buffer_Full, 
	// Unknown means that an error has occurred but cannot be categorized
	Unknown, 
	// Empty is returned when a procedure has not been implemented for an io.Stream
	Empty          = -1, 
}

Flush_Proc ¶

Flush_Proc :: proc "odin" (s: Stream) -> Error

Flusher ¶

Flusher :: struct {
	stream: Stream,
}

Limited_Reader ¶

Limited_Reader :: struct {
	r: Reader,
	// underlying reader
	n: i64,
}
 

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.

Multi_Reader ¶

Multi_Reader :: struct {
	readers: [dynamic]Reader,
}

Multi_Writer ¶

Multi_Writer :: struct {
	writers: [dynamic]Writer,
}

Read_At_Proc ¶

Read_At_Proc :: proc "odin" (using s: Stream, p: []u8, off: i64) -> (n: int, err: Error)

Read_Byte_Proc ¶

Read_Byte_Proc :: proc "odin" (s: Stream) -> (u8, Error)

Read_Closer ¶

Read_Closer :: struct {
	stream: Stream,
}

Read_From_Proc ¶

Read_From_Proc :: proc "odin" (using s: Stream, r: Reader) -> (n: i64, err: Error)

Read_Proc ¶

Read_Proc :: proc "odin" (using s: Stream, p: []u8) -> (n: int, err: Error)

Read_Rune_Proc ¶

Read_Rune_Proc :: proc "odin" (s: Stream) -> (ch: rune, size: int, err: Error)

Read_Write_Closer ¶

Read_Write_Closer :: struct {
	stream: Stream,
}

Read_Write_Seeker ¶

Read_Write_Seeker :: struct {
	stream: Stream,
}

Read_Writer ¶

Read_Writer :: struct {
	stream: Stream,
}

Reader ¶

Reader :: struct {
	stream: Stream,
}

Reader_At ¶

Reader_At :: struct {
	stream: Stream,
}

Reader_From ¶

Reader_From :: struct {
	stream: Stream,
}

Section_Reader ¶

Section_Reader :: struct {
	r:     Reader_At,
	base:  i64,
	off:   i64,
	limit: i64,
}
 

Section_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
}
 

Seek whence values

Seek_Proc ¶

Seek_Proc :: proc "odin" (using s: Stream, offset: i64, whence: Seek_From) -> (n: i64, err: Error)

Seeker ¶

Seeker :: struct {
	stream: Stream,
}

Size_Proc ¶

Size_Proc :: proc "odin" (s: Stream) -> i64

Stream ¶

Stream :: struct {
	stream_vtable: ^Stream_VTable,
	stream_data:   rawptr,
}

Stream_VTable ¶

Stream_VTable :: struct {
	impl_close:       Close_Proc,
	impl_flush:       Flush_Proc,
	impl_seek:        Seek_Proc,
	impl_size:        Size_Proc,
	impl_read:        Read_Proc,
	impl_read_at:     Read_At_Proc,
	impl_read_byte:   Read_Byte_Proc,
	impl_read_rune:   Read_Rune_Proc,
	impl_write_to:    Write_To_Proc,
	impl_write:       Write_Proc,
	impl_write_at:    Write_At_Proc,
	impl_write_byte:  Write_Byte_Proc,
	impl_write_rune:  Write_Rune_Proc,
	impl_read_from:   Read_From_Proc,
	impl_unread_byte: Unread_Byte_Proc,
	impl_unread_rune: Unread_Rune_Proc,
	impl_destroy:     Destroy_Proc,
}

Tee_Reader ¶

Tee_Reader :: struct {
	r: Reader,
	w: Writer,
}

Unread_Byte_Proc ¶

Unread_Byte_Proc :: proc "odin" (s: Stream) -> Error

Unread_Rune_Proc ¶

Unread_Rune_Proc :: proc "odin" (s: Stream) -> Error

Write_At_Proc ¶

Write_At_Proc :: proc "odin" (using s: Stream, p: []u8, off: i64) -> (n: int, err: Error)

Write_Byte_Proc ¶

Write_Byte_Proc :: proc "odin" (using s: Stream, c: u8) -> Error

Write_Closer ¶

Write_Closer :: struct {
	stream: Stream,
}

Write_Flush_Closer ¶

Write_Flush_Closer :: struct {
	stream: Stream,
}

Write_Flusher ¶

Write_Flusher :: struct {
	stream: Stream,
}

Write_Proc ¶

Write_Proc :: proc "odin" (using s: Stream, p: []u8) -> (n: int, err: Error)

Write_Rune_Proc ¶

Write_Rune_Proc :: proc "odin" (using s: Stream, r: rune) -> (size: int, err: Error)

Write_Seeker ¶

Write_Seeker :: struct {
	stream: Stream,
}

Write_To_Proc ¶

Write_To_Proc :: proc "odin" (using s: Stream, w: Writer) -> (n: i64, err: Error)

Writer ¶

Writer :: struct {
	stream: Stream,
}

Writer_At ¶

Writer_At :: struct {
	stream: Stream,
}

Writer_To ¶

Writer_To :: struct {
	stream: Stream,
}

Constants

This section is empty.

Variables

This section is empty.

Procedures

close ¶

close :: proc "odin" (s: Closer) -> Error {…}
 

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

copy ¶

copy :: proc "odin" (dst: Writer, src: Reader) -> (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 ¶

copy_buffer :: proc "odin" (dst: Writer, src: Reader, 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 ¶

copy_n :: proc "odin" (dst: Writer, src: Reader, 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 IFF err == nil

destroy ¶

destroy :: proc "odin" (s: Stream) -> Error {…}

flush ¶

flush :: proc "odin" (s: Flusher) -> Error {…}

limited_reader_init ¶

limited_reader_init :: proc "odin" (l: ^Limited_Reader, r: Reader, n: i64) -> Reader {…}

limited_reader_to_reader ¶

limited_reader_to_reader :: proc "odin" (l: ^Limited_Reader) -> (r: Reader) {…}

multi_reader_destroy ¶

multi_reader_destroy :: proc "odin" (mr: ^Multi_Reader) {…}

multi_reader_init ¶

multi_reader_init :: proc "odin" (mr: ^Multi_Reader, readers: ..Reader, allocator := context.allocator) -> (r: Reader) {…}

multi_writer_destroy ¶

multi_writer_destroy :: proc "odin" (mw: ^Multi_Writer) {…}

multi_writer_init ¶

multi_writer_init :: proc "odin" (mw: ^Multi_Writer, writers: ..Writer, allocator := context.allocator) -> (out: Writer) {…}

n_wrapper ¶

n_wrapper :: proc "odin" (n: int, err: Error, bytes_processed: ^int) -> Error {…}

read ¶

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

read reads up to len(p) bytes into s. 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 "odin" (r: Reader_At, 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 ¶

read_at_least :: proc "odin" (r: Reader, 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_byte ¶

read_byte :: proc "odin" (r: Reader, n_read: ^int = nil) -> (b: u8, err: Error) {…}
 

read_byte reads and returns the next byte from r.

read_from ¶

read_from :: proc "odin" (w: Reader_From, r: Reader) -> (n: i64, err: Error) {…}

read_full ¶

read_full :: proc "odin" (r: Reader, buf: []u8) -> (n: int, err: Error) {…}
 

read_full expected exactly len(buf) bytes from r into buf.

read_ptr ¶

read_ptr :: proc "odin" (r: Reader, p: rawptr, byte_size: int, n_read: ^int = nil) -> (n: int, err: Error) {…}

read_ptr_at ¶

read_ptr_at :: proc "odin" (r: Reader_At, p: rawptr, byte_size: int, offset: i64, n_read: ^int = nil) -> (n: int, err: Error) {…}

read_rune ¶

read_rune :: proc "odin" (br: Reader, 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.

section_reader_init ¶

section_reader_init :: proc "odin" (s: ^Section_Reader, r: Reader_At, off: i64, n: i64) {…}

section_reader_to_stream ¶

section_reader_to_stream :: proc "odin" (s: ^Section_Reader) -> (out: Stream) {…}

seek ¶

seek :: proc "odin" (s: Seeker, 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 ¶

size :: proc "odin" (s: Stream) -> i64 {…}
 

size 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 "odin" (t: ^Tee_Reader, r: Reader, w: Writer, allocator := context.allocator) -> Reader {…}
 

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

tee_reader_to_reader ¶

tee_reader_to_reader :: proc "odin" (t: ^Tee_Reader) -> (r: Reader) {…}

to_closer ¶

to_closer :: proc "odin" (s: Stream) -> (c: Closer, ok: bool = true) #optional_ok {…}

to_flusher ¶

to_flusher :: proc "odin" (s: Stream) -> (f: Flusher, ok: bool = true) #optional_ok {…}

to_read_closer ¶

to_read_closer :: proc "odin" (s: Stream) -> (r: Read_Closer, ok: bool = true) #optional_ok {…}

to_read_write_closer ¶

to_read_write_closer :: proc "odin" (s: Stream) -> (r: Read_Write_Closer, ok: bool = true) #optional_ok {…}

to_read_write_seeker ¶

to_read_write_seeker :: proc "odin" (s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) #optional_ok {…}

to_read_writer ¶

to_read_writer :: proc "odin" (s: Stream) -> (r: Read_Writer, ok: bool = true) #optional_ok {…}

to_reader ¶

to_reader :: proc "odin" (s: Stream) -> (r: Reader, ok: bool = true) #optional_ok {…}

to_reader_at ¶

to_reader_at :: proc "odin" (s: Stream) -> (r: Reader_At, ok: bool = true) #optional_ok {…}

to_reader_from ¶

to_reader_from :: proc "odin" (s: Stream) -> (r: Reader_From, ok: bool = true) #optional_ok {…}

to_seeker ¶

to_seeker :: proc "odin" (s: Stream) -> (seeker: Seeker, ok: bool = true) #optional_ok {…}

to_write_closer ¶

to_write_closer :: proc "odin" (s: Stream) -> (w: Write_Closer, ok: bool = true) #optional_ok {…}

to_write_flush_closer ¶

to_write_flush_closer :: proc "odin" (s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) #optional_ok {…}

to_write_flusher ¶

to_write_flusher :: proc "odin" (s: Stream) -> (w: Write_Flusher, ok: bool = true) #optional_ok {…}

to_write_seeker ¶

to_write_seeker :: proc "odin" (s: Stream) -> (w: Write_Seeker, ok: bool = true) #optional_ok {…}

to_writer ¶

to_writer :: proc "odin" (s: Stream) -> (w: Writer, ok: bool = true) #optional_ok {…}

to_writer_at ¶

to_writer_at :: proc "odin" (s: Stream) -> (w: Writer_At, ok: bool = true) #optional_ok {…}

to_writer_to ¶

to_writer_to :: proc "odin" (s: Stream) -> (w: Writer_To, ok: bool = true) #optional_ok {…}

unread_byte ¶

unread_byte :: proc "odin" (s: Stream) -> Error {…}

unread_rune ¶

unread_rune :: proc "odin" (s: Writer) -> Error {…}

write ¶

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

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

write_at ¶

write_at :: proc "odin" (w: Writer_At, 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_byte ¶

write_byte :: proc "odin" (w: Writer, c: u8, n_written: ^int = nil) -> Error {…}

write_encoded_rune ¶

write_encoded_rune :: proc "odin" (w: Writer, r: rune, write_quote: bool = true, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_escaped_rune ¶

write_escaped_rune :: proc "odin" (w: Writer, r: rune, quote: u8, html_safe: bool = false, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_f16 ¶

write_f16 :: proc "odin" (w: Writer, val: f16, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_f32 ¶

write_f32 :: proc "odin" (w: Writer, val: f32, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_f64 ¶

write_f64 :: proc "odin" (w: Writer, val: f64, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_i128 ¶

write_i128 :: proc "odin" (w: Writer, i: i128, base: int = 10, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_i64 ¶

write_i64 :: proc "odin" (w: Writer, i: i64, base: int = 10, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_int ¶

write_int :: proc "odin" (w: Writer, i: int, base: int = 10, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_ptr ¶

write_ptr :: proc "odin" (w: Writer, p: rawptr, byte_size: int, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_ptr_at ¶

write_ptr_at :: proc "odin" (w: Writer_At, p: rawptr, byte_size: int, offset: i64, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_quoted_rune ¶

write_quoted_rune :: proc "odin" (w: Writer, r: rune) -> (n: int) {…}
 

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

write_quoted_string ¶

write_quoted_string :: proc "odin" (w: Writer, str: string, quote: u8 = '"', n_written: ^int = nil) -> (n: int, err: Error) {…}

write_rune ¶

write_rune :: proc "odin" (s: Writer, r: rune, n_written: ^int = nil) -> (size: int, err: Error) {…}
 

write_rune writes a UTF-8 encoded rune to w.

write_string ¶

write_string :: proc "odin" (s: Writer, str: string, n_written: ^int = nil) -> (n: int, err: Error) {…}
 

write_string writes the contents of the string s to w.

write_to ¶

write_to :: proc "odin" (r: Writer_To, w: Writer) -> (n: i64, err: Error) {…}

write_u128 ¶

write_u128 :: proc "odin" (w: Writer, i: u128, base: int = 10, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_u64 ¶

write_u64 :: proc "odin" (w: Writer, i: u64, base: int = 10, n_written: ^int = nil) -> (n: int, err: Error) {…}

write_uint ¶

write_uint :: proc "odin" (w: Writer, i: uint, base: int = 10, n_written: ^int = nil) -> (n: int, err: Error) {…}

Procedure Groups

This section is empty.

Source Files

Generation Information

Generated with odin version dev-2022-10 (vendor "odin") Windows_amd64 @ 2022-10-05 21:11:47.336171000 +0000 UTC