const SeekStart … const SeekCurrent … const SeekEnd … var ErrShortWrite … var errInvalidWrite … var ErrShortBuffer … var EOF … var ErrUnexpectedEOF … var ErrNoProgress … type Reader … type Writer … type Closer … type Seeker … type ReadWriter … type ReadCloser … type WriteCloser … type ReadWriteCloser … type ReadSeeker … type ReadSeekCloser … type WriteSeeker … type ReadWriteSeeker … type ReaderFrom … type WriterTo … type ReaderAt … type WriterAt … type ByteReader … type ByteScanner … type ByteWriter … type RuneReader … type RuneScanner … type StringWriter … // WriteString writes the contents of the string s to w, which accepts a slice of bytes. // If w implements [StringWriter], [StringWriter.WriteString] is invoked directly. // Otherwise, [Writer.Write] is called exactly once. func WriteString(w Writer, s string) (n int, err error) { … } // ReadAtLeast 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. // The error is EOF only if no bytes were read. // If an EOF happens after reading fewer than min bytes, // ReadAtLeast returns [ErrUnexpectedEOF]. // If min is greater than the length of buf, ReadAtLeast returns [ErrShortBuffer]. // On return, n >= min if and only if err == nil. // If r returns an error having read at least min bytes, the error is dropped. func ReadAtLeast(r Reader, buf []byte, min int) (n int, err error) { … } // ReadFull reads exactly len(buf) bytes from r into buf. // It returns the number of bytes copied and an error if fewer bytes were read. // The error is EOF only if no bytes were read. // If an EOF happens after reading some but not all the bytes, // ReadFull returns [ErrUnexpectedEOF]. // On return, n == len(buf) if and only if err == nil. // If r returns an error having read at least len(buf) bytes, the error is dropped. func ReadFull(r Reader, buf []byte) (n int, err error) { … } // CopyN copies n bytes (or until an error) from src to dst. // It returns the number of bytes copied and the earliest // error encountered while copying. // On return, written == n if and only if err == nil. // // If dst implements [ReaderFrom], the copy is implemented using it. func CopyN(dst Writer, src Reader, n int64) (written int64, err error) { … } // Copy copies from src to dst until either EOF is reached // on src or an error occurs. It returns the number of bytes // copied and the first error encountered while copying, if any. // // A successful Copy returns err == nil, not err == EOF. // Because Copy is defined to read from src until EOF, it does // not treat an EOF from Read as an error to be reported. // // If src implements [WriterTo], // the copy is implemented by calling src.WriteTo(dst). // Otherwise, if dst implements [ReaderFrom], // the copy is implemented by calling dst.ReadFrom(src). func Copy(dst Writer, src Reader) (written int64, err error) { … } // CopyBuffer is identical to Copy except that it stages through the // provided buffer (if one is required) rather than allocating a // temporary one. If buf is nil, one is allocated; otherwise if it has // zero length, CopyBuffer panics. // // If either src implements [WriterTo] or dst implements [ReaderFrom], // buf will not be used to perform the copy. func CopyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) { … } // copyBuffer is the actual implementation of Copy and CopyBuffer. // if buf is nil, one is allocated. func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) { … } // LimitReader returns a Reader that reads from r // but stops with EOF after n bytes. // The underlying implementation is a *LimitedReader. func LimitReader(r Reader, n int64) Reader { … } type LimitedReader … func (l *LimitedReader) Read(p []byte) (n int, err error) { … } // NewSectionReader returns a [SectionReader] that reads from r // starting at offset off and stops with EOF after n bytes. func NewSectionReader(r ReaderAt, off int64, n int64) *SectionReader { … } type SectionReader … func (s *SectionReader) Read(p []byte) (n int, err error) { … } var errWhence … var errOffset … func (s *SectionReader) Seek(offset int64, whence int) (int64, error) { … } func (s *SectionReader) ReadAt(p []byte, off int64) (n int, err error) { … } // Size returns the size of the section in bytes. func (s *SectionReader) Size() int64 { … } // Outer returns the underlying [ReaderAt] and offsets for the section. // // The returned values are the same that were passed to [NewSectionReader] // when the [SectionReader] was created. func (s *SectionReader) Outer() (r ReaderAt, off int64, n int64) { … } type OffsetWriter … // NewOffsetWriter returns an [OffsetWriter] that writes to w // starting at offset off. func NewOffsetWriter(w WriterAt, off int64) *OffsetWriter { … } func (o *OffsetWriter) Write(p []byte) (n int, err error) { … } func (o *OffsetWriter) WriteAt(p []byte, off int64) (n int, err error) { … } func (o *OffsetWriter) Seek(offset int64, whence int) (int64, error) { … } // TeeReader returns a [Reader] that writes to w what it reads from r. // All reads from r performed through it are matched with // corresponding writes to w. There is no internal buffering - // the write must complete before the read completes. // Any error encountered while writing is reported as a read error. func TeeReader(r Reader, w Writer) Reader { … } type teeReader … func (t *teeReader) Read(p []byte) (n int, err error) { … } var Discard … type discard … var _ … func (discard) Write(p []byte) (int, error) { … } func (discard) WriteString(s string) (int, error) { … } var blackHolePool … func (discard) ReadFrom(r Reader) (n int64, err error) { … } // NopCloser returns a [ReadCloser] with a no-op Close method wrapping // the provided [Reader] r. // If r implements [WriterTo], the returned [ReadCloser] will implement [WriterTo] // by forwarding calls to r. func NopCloser(r Reader) ReadCloser { … } type nopCloser … func (nopCloser) Close() error { … } type nopCloserWriterTo … func (nopCloserWriterTo) Close() error { … } func (c nopCloserWriterTo) WriteTo(w Writer) (n int64, err error) { … } // ReadAll reads from r until an error or EOF and returns the data it read. // A successful call returns err == nil, not err == EOF. Because ReadAll is // defined to read from src until EOF, it does not treat an EOF from Read // as an error to be reported. func ReadAll(r Reader) ([]byte, error) { … }