safeio

package
v1.15.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: Apache-2.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitReached = fmt.Errorf("read limit reached")

ErrLimitReached indicates that ReadAllLimit has reached its limit before completing a full read of the io.Reader.

Functions

func ReadAllLimit

func ReadAllLimit(r io.Reader, n ByteSize) ([]byte, error)

ReadAllLimit reads from r until an error, EOF, or after n bytes and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAllLimit is defined to read from src until EOF it does not treat an EOF from Read as an error to be reported. If the limit is reached ReadAllLimit will return ErrLimitReached as an error.

Types

type ByteSize

type ByteSize float64

ByteSize expresses the size of bytes

const (

	// KB is a Kilobyte
	KB ByteSize = 1 << (10 * iota)
	// MB is a Megabyte
	MB
	// GB is a Gigabyte
	GB
	// TB is a Terabyte
	TB
	// PB is a Petabyte
	PB
	// EB is an Exabyte
	EB
	// ZB is a Zettabyte
	ZB
	// YB is a Yottabyte
	YB
)

func (ByteSize) String

func (b ByteSize) String() string

String converts a ByteSize to a string

Jump to

Keyboard shortcuts

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