utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Multiwriter that does not error on a single error

Index

Constants

View Source
const TmpDirSubDirectory = "__updater__001020"

Variables

View Source
var ErrTooLarge = errors.New("bytes.Buffer: too large")

ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.

Functions

func Assert added in v0.4.0

func Assert(condition bool, message string, args ...any)

func Copy

func Copy(src string, dst string) error

TODO this should move if possible for the use case needed

func CopyFromReader

func CopyFromReader(src io.Reader, dst string) error

func CreateFile

func CreateFile(rc io.ReadCloser, length int64, path string) (resultPath string, err error)

func CreateTempFile added in v0.4.0

func CreateTempFile() (path string, file *os.File, err error)

func Ignore2 added in v0.1.3

func Ignore2[T, V any](a T, b V) T

func MultiWriter added in v0.2.19

func MultiWriter(writers ...io.Writer) io.Writer

func RenameSafe

func RenameSafe(oldpath string, newpath string) error

func StripAnsi added in v0.1.3

func StripAnsi(s string) string

func StripAnsiBytes added in v0.1.3

func StripAnsiBytes(b []byte) []byte

func TempDirectory added in v0.4.0

func TempDirectory() string

func Unzip

func Unzip(path string) error

func ValidPath

func ValidPath(path string) bool

Types

type StreamBuffer added in v0.0.10

type StreamBuffer struct {
	End atomic.Bool
	// contains filtered or unexported fields
}

A StreamBuffer is a variable-sized buffer of bytes with StreamBuffer.Read and StreamBuffer.Write methods. The zero value for StreamBuffer is an empty buffer ready to use.

func (*StreamBuffer) Bytes added in v0.2.0

func (b *StreamBuffer) Bytes() []byte

TODO should i return a copy of the bytes? is this thread safe (i dont think so)? but copying the data can be slow because i plan to call this functions very often

func (*StreamBuffer) Len added in v0.0.10

func (b *StreamBuffer) Len() int

Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).

func (*StreamBuffer) Read added in v0.0.10

func (b *StreamBuffer) Read(p []byte) (n int, err error)

Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.

func (*StreamBuffer) Reset added in v0.0.10

func (b *StreamBuffer) Reset()

Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as [StreamBuffer.Truncate](0).

func (*StreamBuffer) Write added in v0.0.10

func (b *StreamBuffer) Write(p []byte) (n int, err error)

Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.

type SwapSlice added in v0.2.19

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

efficient delete slice implementation with no element order garanties

func (*SwapSlice[T]) Append added in v0.2.19

func (s *SwapSlice[T]) Append(e ...T)

func (SwapSlice[T]) Len added in v0.2.19

func (s SwapSlice[T]) Len() int

func (*SwapSlice[T]) Remove added in v0.2.19

func (s *SwapSlice[T]) Remove(i int)

func (SwapSlice[T]) Slice added in v0.2.19

func (s SwapSlice[T]) Slice() []T

Jump to

Keyboard shortcuts

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