safeio

package
v1.61.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package safeio provides functions similar to utilities in built-in io package but with safety nets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextualWriter added in v1.25.0

func ContextualWriter(ctx context.Context, writer io.Writer) io.Writer

ContextualWriter returns a writer which is context aware. Context state is checked BEFORE every Write.

func ConvertIOError added in v1.25.0

func ConvertIOError(err error) (newErr error)

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 to.

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 to.

func NewByteReader added in v1.25.0

func NewByteReader(ctx context.Context, someBytes []byte) io.Reader

NewByteReader return a byte reader which is context aware.

func NewContextualReader added in v1.25.0

func NewContextualReader(ctx context.Context, reader io.Reader) io.Reader

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

func ReadAll(ctx context.Context, src io.Reader) ([]byte, error)

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 WriteString

func WriteString(ctx context.Context, dst io.Writer, s string) (n int, err error)

WriteString writes a string to dst similarly to io.WriteString but with context control to stop when asked to.

Types

This section is empty.

Jump to

Keyboard shortcuts

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