Documentation ¶
Overview ¶
Package safeio provides functions similar to utilities in built-in io package but with safety nets.
Index ¶
- 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 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 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 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 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
Types ¶
This section is empty.