Skip to content

std/io/hostio

import "github.com/eugenioenko/goalchemy/std/io/hostio"

Package hostio adapts host streams passed to library exports as std/io interfaces. The compiler includes it in libraries whose exports take std/io parameters; programs do not import it directly. Each operation is a host callback named “goalchemy.stream.<id>” carrying a one-byte opcode: ‘r’ with an 8-byte count, ‘w’ with data, ‘s’ with an 8-byte offset and 1-byte whence, or ‘c’. Every reply starts with a status byte: 0 for success, 1 for a read that reached end of stream, or 2 for a host error followed by its message. Read data, or the 8-byte big-endian write count or seek position, follows a success status.

const MaxChunk = 128<<10 - 16

MaxChunk bounds the bytes moved by one host operation, within every target’s callback reply limit.

const MaxView = 1 << 20

MaxView bounds the bytes one host read of a source stream returns.

func CloseView(c io.Closer) error

CloseView closes c for a host stream view.

func ReadCloser(id int64) io.ReadCloser

ReadCloser returns the host stream id as an io.ReadCloser.

func ReadSeekCloser(id int64) io.ReadSeekCloser

ReadSeekCloser returns the host stream id as an io.ReadSeekCloser.

func ReadSeeker(id int64) io.ReadSeeker

ReadSeeker returns the host stream id as an io.ReadSeeker.

func ReadView(r io.Reader, n int) ([]byte, bool, error)

ReadView reads at most n bytes from r for a host stream view. It retries empty reads, so it returns data, end of stream, or an error. eof reports that r returned io.EOF; data read before it is returned with it.

func ReadWriter(id int64) io.ReadWriter

ReadWriter returns the host stream id as an io.ReadWriter.

func Reader(id int64) io.Reader

Reader returns the host stream id as an io.Reader.

func SeekView(s io.Seeker, offset int64, whence int) (int64, error)

SeekView seeks s for a host stream view.

func WriteCloser(id int64) io.WriteCloser

WriteCloser returns the host stream id as an io.WriteCloser.

func WriteSeeker(id int64) io.WriteSeeker

WriteSeeker returns the host stream id as an io.WriteSeeker.

func WriteView(w io.Writer, p []byte) (int, error)

WriteView writes all of p to w for a host stream view.

func Writer(id int64) io.Writer

Writer returns the host stream id as an io.Writer.

type Stream struct {
}

Stream is a host stream identified by a per-call registry number.

func (s *Stream) Close() error
func (s *Stream) Read(p []byte) (int, error)
func (s *Stream) Seek(offset int64, whence int) (int64, error)
func (s *Stream) Write(p []byte) (int, error)