ioutils

package
v0.0.0-...-5c7516f Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BYTE = 1 << (10 * iota)
	KILOBYTE
	MEGABYTE
	GIGABYTE
	TERABYTE
	PETABYTE
	EXABYTE
)

Variables

View Source
var InvalidByteQuantityError = errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB")

Functions

func ByteSize

func ByteSize(bytes uint64) string

ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:

E: Exabyte
P: Petabyte
T: Terabyte
G: Gigabyte
M: Megabyte
K: Kilobyte
B: Byte

The unit that results in the smallest number greater than or equal to 1 is always chosen.

func Clear

func Clear(p []byte)

func ClearRange

func ClearRange(p []byte, start, end int)

func ExistFile

func ExistFile(filePath string) (ok bool)

func ReadRegion

func ReadRegion(reader io.ReaderAt, offset int64, capacity int64) (p []byte, err error)

func SyncDir

func SyncDir(dir string) (err error)

func ToBytes

func ToBytes(s string) (uint64, error)

ToBytes parses a string formatted by ByteSize as bytes. Note binary-prefixed and SI prefixed units both mean a base-2 units KB = K = KiB = 1024 MB = M = MiB = 1024 * K GB = G = GiB = 1024 * M TB = T = TiB = 1024 * G PB = P = PiB = 1024 * T EB = E = EiB = 1024 * P

func ToMegabytes

func ToMegabytes(s string) (uint64, error)

ToMegabytes parses a string formatted by ByteSize as megabytes.

func WriteRegion

func WriteRegion(writer io.WriterAt, offset int64, p []byte) (err error)

Types

type File

type File struct {
	// contains filtered or unexported fields
}

func OpenFile

func OpenFile(filePath string) (file *File, err error)

func (*File) Close

func (f *File) Close() (err error)

func (*File) File

func (f *File) File() (file *os.File)

func (*File) ReadAt

func (f *File) ReadAt(offset int64, capacity int64) (p []byte, err error)

func (*File) ReadRegion

func (f *File) ReadRegion(offset int64, capacity int64) (region FileRegion, err error)

func (*File) Size

func (f *File) Size() (n int64, err error)

func (*File) Sync

func (f *File) Sync() (err error)

func (*File) WriteAt

func (f *File) WriteAt(offset int64, p []byte) (err error)

type FileRegion

type FileRegion interface {
	io.ReaderAt
	io.ReadCloser
	Bytes() (p []byte)
}

Jump to

Keyboard shortcuts

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