safeio

package module
v1.173.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

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

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cat

func Cat(ctx context.Context, dst io.Writer, src ...io.Reader) (copied int64, err error)

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

func CatN(ctx context.Context, dst io.Writer, n int64, src ...io.Reader) (copied int64, err error)

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

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

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.

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

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

NewByteReader return a byte reader which is context aware.

func NewContextualMultipleReader

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

func NewContextualReadCloser

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

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

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 SafeCopyDataWithContext

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

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.

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