utils

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPathExists

func CheckPathExists(chkPath string) bool

func CompressGZIP

func CompressGZIP(data []byte) (compressedData []byte, err error)

func CompressWhenNeeded

func CompressWhenNeeded(data []byte) (resultData []byte, compression *string, err error)

TODO: check if it's worth trying to compress the data prior to compressing it (e.g: using entropy algorithms) This would save some CPU usage client side TODO: have telemetry data type be passed in as a parameter to further check if we should compress data and which algorithm to use (e.g: deflate or gzip)

func DecompressGZIP

func DecompressGZIP(compressedData []byte) (decompressedData []byte, err error)

func DecompressWhenNeeded

func DecompressWhenNeeded(data []byte, compression sql.NullString) (resultData []byte, err error)

TODO: have telemetry data type be passed in as a parameter to further check if we should decompress data and which algorithm to use (e.g: deflate or gzip)

func GetMd5Hash

func GetMd5Hash(target any) (hashed string, err error)

func GetSha256Hash

func GetSha256Hash(target any) (hashed string, err error)

func GetSha512Hash

func GetSha512Hash(target any) (hashed string, err error)

func HumanReadableSize

func HumanReadableSize(data []byte) string

Types

type FileManager

type FileManager interface {
	// init a new file manager
	Init(filePath string, owner string, group string, perm os.FileMode) error

	// init from an existing file
	UseExistingFile(filePath string) error

	// backups management
	EnableBackups()
	DisableBackups()
	BackupsEnabled() bool

	// file path
	Path() string
	SetPath(filePath string) error
	Exists() (bool, error)
	Accessible() (bool, error)

	// file ownership and permissions
	User() string
	SetUser(string) error
	Group() string
	SetGroup(string) error
	Perm() os.FileMode
	SetPerm(perm os.FileMode) error

	// lock management
	Lock() error
	Unlock() error
	IsLocked() bool

	// data operations
	Open(create bool) error
	Create() error
	Read() ([]byte, error)
	Update(updatedContent []byte) error
	Backup() error
	Delete() error
	Close() error
}

FileManager interface

type ManagedFile

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

ManagedFile

func NewManagedFile

func NewManagedFile() *ManagedFile

func (*ManagedFile) Accessible added in v0.1.2

func (fm *ManagedFile) Accessible() (accessible bool, err error)

func (*ManagedFile) Backup

func (fm *ManagedFile) Backup() (err error)

func (*ManagedFile) BackupsEnabled

func (fm *ManagedFile) BackupsEnabled() bool

func (*ManagedFile) Close

func (fm *ManagedFile) Close() (err error)

func (*ManagedFile) Create

func (fm *ManagedFile) Create() (err error)

func (*ManagedFile) Delete

func (fm *ManagedFile) Delete() (err error)

func (*ManagedFile) DisableBackups

func (fm *ManagedFile) DisableBackups()

func (*ManagedFile) EnableBackups

func (fm *ManagedFile) EnableBackups()

func (*ManagedFile) Exists

func (fm *ManagedFile) Exists() (exists bool, err error)

func (*ManagedFile) Group

func (fm *ManagedFile) Group() string

func (*ManagedFile) Init

func (fm *ManagedFile) Init(filePath, user, group string, perm os.FileMode) (err error)

func (*ManagedFile) IsLocked

func (fm *ManagedFile) IsLocked() bool

func (*ManagedFile) Lock

func (fm *ManagedFile) Lock() (err error)

func (*ManagedFile) Open

func (fm *ManagedFile) Open(create bool) (err error)

func (*ManagedFile) Path

func (fm *ManagedFile) Path() string

func (*ManagedFile) Perm

func (fm *ManagedFile) Perm() os.FileMode

func (*ManagedFile) Read

func (fm *ManagedFile) Read() (content []byte, err error)

func (*ManagedFile) SetGroup

func (fm *ManagedFile) SetGroup(group string) (err error)

func (*ManagedFile) SetPath

func (fm *ManagedFile) SetPath(path string) (err error)

func (*ManagedFile) SetPerm

func (fm *ManagedFile) SetPerm(perm os.FileMode) (err error)

func (*ManagedFile) SetUser

func (fm *ManagedFile) SetUser(user string) (err error)

func (*ManagedFile) Unlock

func (fm *ManagedFile) Unlock() (err error)

func (*ManagedFile) Update

func (fm *ManagedFile) Update(updatedContent []byte) (err error)

func (*ManagedFile) UseExistingFile

func (fm *ManagedFile) UseExistingFile(path string) (err error)

func (*ManagedFile) User

func (fm *ManagedFile) User() string

Jump to

Keyboard shortcuts

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