iotools

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const EOFReader = eofreader(0)

EOFReader is an io.Reader with Read always giving an io.EOF.

Variables

This section is empty.

Functions

func Drain

func Drain(r io.Reader) (int64, error)

Drain reads from r until either io.EOF is reached on r or an error occurs. It returns the number of bytes read and the first error encountered while reading, if any. Note that on completing successful drain the second return value is nil and not io.EOF. Because Drain is defined to read from r until io.EOF, it does not treat an io.EOF from Read as an error to be reported.

func ExactReader

func ExactReader(r io.Reader, n int64) io.Reader

ExactReader returns an io.Reader that reads from r but stops with io.EOF after n bytes, and returns an io.ErrUnexpectedEOF if io.EOF occurs before n bytes have been read.

Types

type ByteCountWriter

type ByteCountWriter struct {
	W io.Writer // The wrapped writer
	N int64     // The number of bytes written to the writer
}

ByteCountWriter wraps an io.Writer and keeps track of the number of bytes that have been written to the wrapped writer.

func (*ByteCountWriter) ReadFrom added in v1.0.4

func (w *ByteCountWriter) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom ReadFrom reads data from r until EOF or error. The return value n is the number of bytes read. Any error except EOF encountered during the read is also returned.

func (*ByteCountWriter) Size

func (w *ByteCountWriter) Size() int64

Size returns the number of bytes that have been written to the writer.

func (*ByteCountWriter) Write

func (w *ByteCountWriter) Write(p []byte) (int, error)

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL