util

package
v0.0.0-...-79395b0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package util contains various utility functions used by other packages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsciizToString

func AsciizToString(data []byte) string

AsciizToString converts a null terminated byte array to a string

func BufreaderAt

func BufreaderAt(r io.ReadSeeker, offset int64) (*bufio.Reader, error)

BufreaderAt is a helper for creating a buffered reader at a position

func CreateFile

func CreateFile(filename string) (*os.File, error)

CreateFile creates a file, adds missing directories

func DecodeString

func DecodeString(bs []byte) ([]byte, error)

func Extensions

func Extensions(filename string) []string

Extensions returns all extensions of a file, e.g. a.tar.gz -> ["gz","tar"]

func HashFile

func HashFile(filename string) ([]byte, error)

HashFile generates a hash for a file with an unspecified algorithm

func HashStream

func HashStream(r io.Reader) ([]byte, error)

HashStream is similar to HashFile but operates on streams

func Mkdir

func Mkdir(path string) error

Mkdir creates directories in a path

func NewEmptyDir

func NewEmptyDir(dirname string) error

NewEmptyDir accepts a new or empty dir and if new creates it

func NewReaderAt

func NewReaderAt(r io.ReadSeeker) io.ReaderAt

NewReaderAt turns a ReadSeeker into a ReaderAt for the rare cases its needed

func ParseNumber

func ParseNumber(str string, bits int) (uint64, error)

ParseNumber parses number from string, handles 0x, 0o and 0b prefixes

func Process

func Process(r io.ByteReader, p func(b uint8, n int) bool) (int, error)

Process will fall p on each byte until it returns false

func ReadUntil

func ReadUntil(r io.Reader, until byte, maxsize int) ([]byte, bool, error)

ReadUntil reads from stream until it sees byte "until" or gathers "maxsize" bytes (ignored if zero or less)

func RegisterFatal

func RegisterFatal(v interface{})

RegisterFatal regiters a fatal error

func RegisterFatalf

func RegisterFatalf(format string, v ...interface{})

RegisterFatalf regiters a fatal error

func RegisterWarningf

func RegisterWarningf(format string, v ...interface{})

RegisterWarningf regiters a warning that will be printed and recorded

func SanitizeFilename

func SanitizeFilename(filename string) string

SanitizeFilename performs file name sanitization

func Warnings

func Warnings() []string

Warnings returns all warnings seen by the library

Types

type FileList

type FileList struct {
	FollowSymlinks bool
	In             []string
}

FileList is a list of files, including files in folders

func (*FileList) Pop

func (fl *FileList) Pop() (string, os.FileInfo, error)

Pop takes a file from the queue

func (*FileList) Push

func (fl *FileList) Push(paths ...string)

Push puts a file in§to the queue

type Function

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

Function represents a call to a golang function with the following format

func(param1, param2, ...) (ret1, ...)

func NewFunction

func NewFunction(name string, fun interface{}) (*Function, error)

func (Function) Call

func (f Function) Call(args []interface{}) ([]interface{}, error)

Call does the actuall function call using golang reflection, after some format and type checking. This function will fail if the parameter and return format do not match. This function will recover panics and report them to RegisterFatalf()

func (Function) Signature

func (f Function) Signature(input bool) []string

func (Function) String

func (f Function) String() string

type FunctionDatabase

type FunctionDatabase struct {
	Functions map[string]*Function
	// contains filtered or unexported fields
}

FunctionDatabase is a database of cuntion with a given prototype

func NewFunctionDatabase

func NewFunctionDatabase(prototype interface{}) (*FunctionDatabase, error)

func (FunctionDatabase) Find

func (db FunctionDatabase) Find(name string) (*Function, bool)

Find finds among registered functions

func (FunctionDatabase) Register

func (db FunctionDatabase) Register(name string, fun interface{}) error

Register registers a user function

type PathType

type PathType int

PathType is type of a path such as /tmp, i.e. wether its a file or a dir etc

const (
	Error PathType = iota
	NoFile
	File
	EmptyDir
	NonEmptyDir
)

func GetPathType

func GetPathType(path string) PathType

GetPathType returns type of a path

type Register

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

func NewRegister

func NewRegister() *Register

func (Register) Get

func (r Register) Get(name string, def interface{}) (interface{}, bool)

func (Register) GetBoolean

func (r Register) GetBoolean(name string, def bool) (bool, bool)

func (Register) GetString

func (r Register) GetString(name string, def string) (string, bool)

func (*Register) Set

func (r *Register) Set(name string, val interface{})

func (Register) SetBoolean

func (r Register) SetBoolean(name string, val bool)

func (Register) SetNumber

func (r Register) SetNumber(name string, val uint64)

func (*Register) SetParent

func (r *Register) SetParent(parent *Register)

func (Register) SetString

func (r Register) SetString(name string, val string)

func (Register) Walk

func (r Register) Walk(visitor func(key string, val interface{}) bool)

Walk all values in the register

type Structured

type Structured struct {
	Reader io.ReadSeeker
	Order  binary.ByteOrder
}

Structured define a file that has a stream and a byteorder

func (Structured) Read

func (bf Structured) Read(data interface{}) error

Read reads structred data from the stream

func (Structured) ReadAt

func (bf Structured) ReadAt(offset int64, data interface{}) error

ReadAt reads structred data from a given offset

Jump to

Keyboard shortcuts

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