std/io
import "github.com/eugenioenko/goalchemy/std/io"Package io provides basic interfaces to I/O primitives and helpers that combine them, matching Go’s io package. Pipe is not provided.
const ( SeekStart = 0 SeekCurrent = 1 SeekEnd = 2)Seek whence values.
var EOF = errors.New("EOF")EOF is the error returned by Read when no more input is available.
var ErrClosedPipe = errors.New("io: read/write on closed pipe")ErrClosedPipe is the error used for read or write operations on a closed pipe.
var ErrNoProgress = errors.New("multiple Read calls return no data or error")ErrNoProgress is returned when many calls to Read have failed to return any data or error.
var ErrShortBuffer = errors.New("short buffer")ErrShortBuffer means that a read required a longer buffer than was provided.
var ErrShortWrite = errors.New("short write")ErrShortWrite means that a write accepted fewer bytes than requested but failed to return an explicit error.
var ErrUnexpectedEOF = errors.New("unexpected EOF")ErrUnexpectedEOF means that EOF was encountered in the middle of reading a fixed-size block or data structure.
func Copy(dst Writer, src Reader) (written int64, err error)Copy copies from src to dst until EOF or an error. A successful Copy returns err == nil, not EOF.
CopyBuffer
Section titled “CopyBuffer”func CopyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error)CopyBuffer is identical to Copy except that it stages through buf. It panics if buf is non-nil and empty.
func CopyN(dst Writer, src Reader, n int64) (written int64, err error)CopyN copies n bytes, or until an error, from src to dst.
ReadAll
Section titled “ReadAll”func ReadAll(r Reader) ([]byte, error)ReadAll reads from r until an error or EOF and returns the data it read. A successful call returns err == nil, not EOF.
ReadAtLeast
Section titled “ReadAtLeast”func ReadAtLeast(r Reader, buf []byte, min int) (n int, err error)ReadAtLeast reads from r into buf until it has read at least min bytes. It returns ErrShortBuffer if min is larger than buf, EOF if no bytes were read, and ErrUnexpectedEOF if EOF happens after reading fewer than min bytes.
ReadFull
Section titled “ReadFull”func ReadFull(r Reader, buf []byte) (n int, err error)ReadFull reads exactly len(buf) bytes from r into buf.
WriteString
Section titled “WriteString”func WriteString(w Writer, s string) (n int, err error)WriteString writes s to w, using w’s WriteString method when it has one.
type ByteReader
Section titled “type ByteReader”type ByteReader interface { ReadByte() (byte, error)}ByteReader wraps the ReadByte method.
type ByteScanner
Section titled “type ByteScanner”type ByteScanner interface { ByteReader UnreadByte() error}ByteScanner adds the UnreadByte method to ByteReader.
type ByteWriter
Section titled “type ByteWriter”type ByteWriter interface { WriteByte(c byte) error}ByteWriter wraps the WriteByte method.
type Closer
Section titled “type Closer”type Closer interface { Close() error}Closer wraps the basic Close method.
type LimitedReader
Section titled “type LimitedReader”type LimitedReader struct { R Reader N int64}LimitedReader reads from R but limits the amount of data returned to just N bytes.
LimitedReader.Read
Section titled “LimitedReader.Read”func (l *LimitedReader) Read(p []byte) (n int, err error)Read reads at most the remaining N bytes.
type OffsetWriter
Section titled “type OffsetWriter”type OffsetWriter struct {}OffsetWriter maps writes at offset base to offset base+off in the underlying WriterAt.
NewOffsetWriter
Section titled “NewOffsetWriter”func NewOffsetWriter(w WriterAt, off int64) *OffsetWriterNewOffsetWriter returns an OffsetWriter that writes to w starting at off.
OffsetWriter.Seek
Section titled “OffsetWriter.Seek”func (o *OffsetWriter) Seek(offset int64, whence int) (int64, error)Seek implements io.Seeker relative to the base offset; SeekEnd is not supported.
OffsetWriter.Write
Section titled “OffsetWriter.Write”func (o *OffsetWriter) Write(p []byte) (n int, err error)Write writes at the current offset and advances it.
OffsetWriter.WriteAt
Section titled “OffsetWriter.WriteAt”func (o *OffsetWriter) WriteAt(p []byte, off int64) (n int, err error)WriteAt writes at off relative to the base offset.
type ReadCloser
Section titled “type ReadCloser”type ReadCloser interface { Reader Closer}ReadCloser groups the basic Read and Close methods.
NopCloser
Section titled “NopCloser”func NopCloser(r Reader) ReadCloserNopCloser returns a ReadCloser with a no-op Close method wrapping r. If r implements WriterTo, the result does too.
type ReadSeekCloser
Section titled “type ReadSeekCloser”type ReadSeekCloser interface { Reader Seeker Closer}ReadSeekCloser groups the basic Read, Seek and Close methods.
type ReadSeeker
Section titled “type ReadSeeker”type ReadSeeker interface { Reader Seeker}ReadSeeker groups the basic Read and Seek methods.
type ReadWriteCloser
Section titled “type ReadWriteCloser”type ReadWriteCloser interface { Reader Writer Closer}ReadWriteCloser groups the basic Read, Write and Close methods.
type ReadWriteSeeker
Section titled “type ReadWriteSeeker”type ReadWriteSeeker interface { Reader Writer Seeker}ReadWriteSeeker groups the basic Read, Write and Seek methods.
type ReadWriter
Section titled “type ReadWriter”type ReadWriter interface { Reader Writer}ReadWriter groups the basic Read and Write methods.
type Reader
Section titled “type Reader”type Reader interface { Read(p []byte) (n int, err error)}Reader wraps the basic Read method.
LimitReader
Section titled “LimitReader”func LimitReader(r Reader, n int64) ReaderLimitReader returns a Reader that reads from r but stops with EOF after n bytes.
MultiReader
Section titled “MultiReader”func MultiReader(readers ...Reader) ReaderMultiReader returns a Reader that is the logical concatenation of readers.
TeeReader
Section titled “TeeReader”func TeeReader(r Reader, w Writer) ReaderTeeReader returns a Reader that writes to w what it reads from r. Any error writing to w is returned as a read error.
type ReaderAt
Section titled “type ReaderAt”type ReaderAt interface { ReadAt(p []byte, off int64) (n int, err error)}ReaderAt wraps the basic ReadAt method.
type ReaderFrom
Section titled “type ReaderFrom”type ReaderFrom interface { ReadFrom(r Reader) (n int64, err error)}ReaderFrom wraps the ReadFrom method.
type RuneReader
Section titled “type RuneReader”type RuneReader interface { ReadRune() (r rune, size int, err error)}RuneReader wraps the ReadRune method.
type RuneScanner
Section titled “type RuneScanner”type RuneScanner interface { RuneReader UnreadRune() error}RuneScanner adds the UnreadRune method to RuneReader.
type SectionReader
Section titled “type SectionReader”type SectionReader struct {}SectionReader implements Read, Seek and ReadAt on a section of an underlying ReaderAt.
NewSectionReader
Section titled “NewSectionReader”func NewSectionReader(r ReaderAt, off int64, n int64) *SectionReaderNewSectionReader returns a SectionReader that reads from r starting at offset off and stops with EOF after n bytes.
SectionReader.Outer
Section titled “SectionReader.Outer”func (s *SectionReader) Outer() (r ReaderAt, off int64, n int64)Outer returns the underlying ReaderAt and offsets of the section.
SectionReader.Read
Section titled “SectionReader.Read”func (s *SectionReader) Read(p []byte) (n int, err error)Read implements io.Reader within the section.
SectionReader.ReadAt
Section titled “SectionReader.ReadAt”func (s *SectionReader) ReadAt(p []byte, off int64) (n int, err error)ReadAt implements io.ReaderAt relative to the section.
SectionReader.Seek
Section titled “SectionReader.Seek”func (s *SectionReader) Seek(offset int64, whence int) (int64, error)Seek implements io.Seeker relative to the section.
SectionReader.Size
Section titled “SectionReader.Size”func (s *SectionReader) Size() int64Size returns the size of the section in bytes.
type Seeker
Section titled “type Seeker”type Seeker interface { Seek(offset int64, whence int) (int64, error)}Seeker wraps the basic Seek method.
type StringWriter
Section titled “type StringWriter”type StringWriter interface { WriteString(s string) (n int, err error)}StringWriter wraps the WriteString method.
type WriteCloser
Section titled “type WriteCloser”type WriteCloser interface { Writer Closer}WriteCloser groups the basic Write and Close methods.
type WriteSeeker
Section titled “type WriteSeeker”type WriteSeeker interface { Writer Seeker}WriteSeeker groups the basic Write and Seek methods.
type Writer
Section titled “type Writer”type Writer interface { Write(p []byte) (n int, err error)}Writer wraps the basic Write method.
var Discard Writer = discard{}Discard is a Writer on which all Write calls succeed without doing anything.
MultiWriter
Section titled “MultiWriter”func MultiWriter(writers ...Writer) WriterMultiWriter creates a writer that duplicates its writes to all the provided writers, stopping at the first error.
type WriterAt
Section titled “type WriterAt”type WriterAt interface { WriteAt(p []byte, off int64) (n int, err error)}WriterAt wraps the basic WriteAt method.
type WriterTo
Section titled “type WriterTo”type WriterTo interface { WriteTo(w Writer) (n int64, err error)}WriterTo wraps the WriteTo method.