Documentation
¶
Overview ¶
Package safeio provides functions similar to utilities in built-in io package but with safety nets.
Index ¶
- func Cat(ctx context.Context, dst io.Writer, src ...io.Reader) (copied int64, err error)
- func CatN(ctx context.Context, dst io.Writer, n int64, src ...io.Reader) (copied int64, err error)
- func ContextualWriter(ctx context.Context, writer io.Writer) io.Writer
- func ConvertIOError(err error) (newErr error)
- func CopyDataWithContext(ctx context.Context, src io.Reader, dst io.Writer) (copied int64, err error)
- func CopyNWithContext(ctx context.Context, src io.Reader, dst io.Writer, n int64) (copied int64, err error)
- func NewByteReader(ctx context.Context, someBytes []byte) io.Reader
- func NewContextualMultipleReader(ctx context.Context, reader ...io.Reader) io.Reader
- func NewContextualReadCloser(ctx context.Context, reader io.ReadCloser) io.ReadCloser
- func NewContextualReader(ctx context.Context, reader io.Reader) io.Reader
- func NewContextualReaderFrom(ctx context.Context, reader io.ReaderFrom) io.ReaderFrom
- func ReadAll(ctx context.Context, src io.Reader) ([]byte, error)
- func ReadAtMost(ctx context.Context, src io.Reader, max int64, bufferCapacity int64) (content []byte, err error)
- func SafeCopyDataWithContext(ctx context.Context, src io.ReadCloser, dst io.Writer) (copied int64, err error)
- func SafeCopyNWithContext(ctx context.Context, src io.ReadCloser, dst io.Writer, n int64) (copied int64, err error)
- func WriteString(ctx context.Context, dst io.Writer, s string) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cat ¶ added in v1.119.1
Cat concatenates bytes from multiple sources to dst. It is intended to provide functionality quite similar to `cat` posix command but with context control.
func CatN ¶ added in v1.119.1
CatN concatenates n bytes from multiple sources to dst. It is intended to provide functionality quite similar to `cat` posix command but with context control.
func ContextualWriter ¶ added in v1.25.0
ContextualWriter returns a writer which is context aware. Context state is checked BEFORE every Write.
func ConvertIOError ¶ added in v1.25.0
ConvertIOError converts an I/O error into common errors.
func CopyDataWithContext ¶
func CopyDataWithContext(ctx context.Context, src io.Reader, dst io.Writer) (copied int64, err error)
CopyDataWithContext copies from src to dst similarly to io.Copy but with context control to stop when asked.
func CopyNWithContext ¶
func CopyNWithContext(ctx context.Context, src io.Reader, dst io.Writer, n int64) (copied int64, err error)
CopyNWithContext copies n bytes from src to dst similarly to io.CopyN but with context control to stop when asked.
func NewByteReader ¶ added in v1.25.0
NewByteReader return a byte reader which is context aware.
func NewContextualMultipleReader ¶ added in v1.119.1
func NewContextualReadCloser ¶ added in v1.121.0
func NewContextualReadCloser(ctx context.Context, reader io.ReadCloser) io.ReadCloser
NewContextualReadCloser returns a readcloser which is context aware. Context state is checked during the read and close is called if the context is cancelled This allows for readers that block on syscalls to be stopped via a context
func NewContextualReader ¶ added in v1.25.0
NewContextualReader returns a reader which is context aware. Context state is checked BEFORE every Read.
func NewContextualReaderFrom ¶ added in v1.25.0
func NewContextualReaderFrom(ctx context.Context, reader io.ReaderFrom) io.ReaderFrom
NewContextualReaderFrom returns a io.ReaderFrom which is context aware. Context state is checked BEFORE every Read, Write, Copy.
func ReadAll ¶
ReadAll reads the whole content of src similarly to io.ReadAll but with context control to stop when asked to.
func ReadAtMost ¶
func ReadAtMost(ctx context.Context, src io.Reader, max int64, bufferCapacity int64) (content []byte, err error)
ReadAtMost reads the content of src and at most max bytes. It provides a functionality close to io.ReadAtLeast but with a different goal. if bufferCapacity is not set i.e. set to a negative value, it will be set by default to max if max is set to a negative value, the entirety of the reader will be read
func SafeCopyDataWithContext ¶ added in v1.121.0
func SafeCopyDataWithContext(ctx context.Context, src io.ReadCloser, dst io.Writer) (copied int64, err error)
SafeCopyDataWithContext copies from src to dst similarly to io.Copy but with context control to stop when asked. Unlike CopyWithContext it requires a ReadCloser, this allows it to stop even if the system is doing a kernel read.
func SafeCopyNWithContext ¶ added in v1.121.0
func SafeCopyNWithContext(ctx context.Context, src io.ReadCloser, dst io.Writer, n int64) (copied int64, err error)
SafeCopyNWithContext copies n bytes from src to dst similarly to io.CopyN but with context control to stop when asked. Unlike CopyNWithContext it requires a ReadCloser, this allows it to stop even if the system is doing a kernel read.
Types ¶
This section is empty.