util

package
v0.0.0-...-ea581e5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoError

func AssertNoError(err error)

func CloneSliceFunc

func CloneSliceFunc[T any](slice []T, copy func(T) T) (out []T)

func FileExists

func FileExists(path string) (exists bool, _ error)

func NewRandomUUIDBytes

func NewRandomUUIDBytes() (out [16]byte)

func Ptr

func Ptr[T any](v T) *T

func ReadUint64

func ReadUint64(reader io.Reader) (value uint64, n int, _ error)

func ReadUint64s

func ReadUint64s(reader io.Reader, vs ...*uint64) (n int, _ error)

func Seq2At

func Seq2At[U, V any](seq iter.Seq2[U, V], idx int) (out1 U, out2 V, exists bool)

func SeqAt

func SeqAt[T any](seq iter.Seq[T], idx int) (out T, exists bool)

func SeqOf

func SeqOf[T any](items ...T) iter.Seq[T]

func ToBytes

func ToBytes(writerTo io.WriterTo) ([]byte, error)

func UUIDFromBytes

func UUIDFromBytes(bytes [16]byte) uuid.UUID

func Uint64FromWord64

func Uint64FromWord64(v Word64) uint64

func ValueFromBytes

func ValueFromBytes[T any, PT ReaderFromPtr[T]](b []byte) (T, error)

func ValueToBytes

func ValueToBytes[T any, PT WriterToPtr[T]](value T) ([]byte, error)

func WriteUint64

func WriteUint64(writer io.Writer, v uint64) (n int, _ error)

func WriteUint64s

func WriteUint64s(writer io.Writer, vs ...uint64) (n int, _ error)

Types

type FileWrapper

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

FileWrapper is a utility class that can be used to read a file starting at an offset. More importantly, compared to a regular os.File, it uses `ReadAt` consistently, which does not mutate the underlying file descriptor state, allowing multiple readers to be safely created over a single file.

func NewFileWrapper

func NewFileWrapper(file *os.File) FileWrapper

func NewFileWrapperAt

func NewFileWrapperAt(file *os.File, offset uint64) FileWrapper

func (*FileWrapper) Copy

func (me *FileWrapper) Copy() FileWrapper

func (*FileWrapper) Read

func (me *FileWrapper) Read(b []byte) (n int, err error)

func (*FileWrapper) Seek

func (me *FileWrapper) Seek(offset int64, whence int) (ret int64, err error)

func (*FileWrapper) Sync

func (me *FileWrapper) Sync() error

func (*FileWrapper) Write

func (me *FileWrapper) Write(b []byte) (n int, err error)

type IOSeeker

type IOSeeker struct {
	io.ReadWriteSeeker
	io.WriterAt
	io.ReaderAt
}

type Optional

type Optional[T any] struct {
	// contains filtered or unexported fields
}

func None

func None[T any]() Optional[T]

func Some

func Some[T any](v T) Optional[T]

func (*Optional[T]) Or

func (me *Optional[T]) Or(defaultValue T) T

func (*Optional[T]) Unpack

func (me *Optional[T]) Unpack() (T, bool)

type ReaderFromPtr

type ReaderFromPtr[M any] interface {
	*M
	io.ReaderFrom
}

type Word64

type Word64 [8]byte

func Uint64ToWord64

func Uint64ToWord64(v uint64) (out Word64)

func (Word64) FromUint64

func (me Word64) FromUint64(v uint64) Word64

func (Word64) Read

func (me Word64) Read(reader io.Reader) (Word64, error)

func (Word64) Uint64

func (me Word64) Uint64() uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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