byteutil

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package byteutil implements functions for the manipulation of byte slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendDecimal

func AppendDecimal(b []byte, v int64, pow int) []byte

AppendDecimal appends the string format of the fixed-point number v, with pow places after the deciaml point, to b and returns the extended buffer. The value appended will be padded with 0's to reach the desired decimal places pow.

func AppendSize

func AppendSize(b []byte, v uint64, size ByteSize) []byte

AppendSize appends the string representation of v bytes scaled to size, with 3 decimal places of precision.

func Btoi

func Btoi(b []byte) int64

Btou is a naive base 10 implementation of strconv.ParseInt that assumes all the bytes of b are numerical characters, and ignores any that aren't.

func Btou

func Btou(b []byte) uint64

Btou is a naive base 10 implementation of strconv.ParseUint that assumes all the bytes of b are numerical characters, and ignores any that aren't.

func Btox

func Btox(b []byte) uint64

Btou is a naive base 16 implementation of strconv.ParseUint that assumes all the bytes of b are numerical characters, and ignores any that aren't.

func Column

func Column(b []byte) (col, rest []byte)

Column splits b by the first space and returns the subslice of b before the space and the remainder of b after the space with spaces trimmed.

func ColumnString

func ColumnString(b []byte) (col string, rest []byte)

ColumnString is the same as Column but returns the subslice before the space as a string

func Columns

func Columns(b []byte, dst ...*[]byte) (n int, rest []byte)

Columns splits b into len(dst) columns using Column and returns the number columns parsed and the remainder of b.

func Equal

func Equal(a, b []byte) bool

Equal is equivalent to bytes.Compare(a, b) == 0.

func Field

func Field(b []byte) (key, val []byte)

Field splits b by the first ':' and returns the subslice of b before the colon with spaces trimmed and the subslice of b after the colon.

func ToLower

func ToLower(b []byte) []byte

ToLower is equivalent to bytes.ToLower but modifies b in place instead of making a copy.

func ToTitle

func ToTitle(b []byte) []byte

ToTitle returns the title case representation of b.

func ToTitleString

func ToTitleString(s string) string

ToTitleString returns the title case representation of s.

func TrimByte

func TrimByte(b []byte, c byte) []byte

TrimByte returns the subslice of b with all leading and trailing occurences of c sliced off.

func WriteDecimal

func WriteDecimal(w io.Writer, v int64, pow int) (n int, err error)

WriteDecimal writes the output of AppendDecimal to w.

func WriteSize

func WriteSize(w io.Writer, v uint64, size ByteSize) (n int, err error)

WriteSize writes the output of AppendSize to w followed by the string representation of size.

Types

type ByteRate

type ByteRate int

A ByteSize is the human-readable representation of a byte count.

const (
	Bps ByteRate = 10 * iota
	KiBps
	MiBps
	GiBps
	TiBps
	PiBps
)

Binary prefix human-readable rates.

func ParseRate

func ParseRate(s string) (ByteRate, error)

ParseSize parses s for the common prefix representation of a ByteRate.

func (ByteRate) MarshalJSON

func (r ByteRate) MarshalJSON() ([]byte, error)

MarshalJSON marshals r into the double-quoted string representation.

func (ByteRate) String

func (r ByteRate) String() string

String returns the string representation of r.

type ByteSize

type ByteSize int

A ByteSize is the human-readable representation of a byte count.

const (
	Bytes ByteSize = 10 * iota
	KiB
	MiB
	GiB
	TiB
	PiB
)

Binary prefix human-readable sizes.

const UnknownSize ByteSize = -1

func ParseSize

func ParseSize(s string) (ByteSize, error)

ParseSize parses s for the common prefix representation of a ByteSize.

func SizeOf

func SizeOf(v uint64) ByteSize

SizeOf returns the largest human-readable ByteSize that can be used to represent v.

func (ByteSize) MarshalJSON

func (s ByteSize) MarshalJSON() ([]byte, error)

MarshalJSON marshals s into the double-quoted string representation.

func (ByteSize) String

func (s ByteSize) String() string

String returns the string representation of s.

type MultiFileReader

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

MultiFileReader implements the io.Reader and io.Closer interfaces by reading the contents of multiple files.

func NewMultiFileReader

func NewMultiFileReader(name ...string) *MultiFileReader

NewMultiFileReader returns a new MultiFileReader that reads from the given files.

func (*MultiFileReader) Close

func (r *MultiFileReader) Close() (err error)

Close implements the io.Closer interface. It closes the currently open file.

func (*MultiFileReader) Read

func (r *MultiFileReader) Read(p []byte) (n int, err error)

Read implements the io.Reader interface. Once the end of a file is read the next call to Read will open the next file. Any errors encountered while opening a file will be returned, and io.EOF is returned once all the files have reached EOF.

Jump to

Keyboard shortcuts

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