fileio

package
v0.0.0-...-330397d Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExist

func CheckExist(filePath string, onNonExist func() error) (err error)

func DataFile

func DataFile(name string) string

func HumanBytes

func HumanBytes[T Number](b T) string

func HumanDuration

func HumanDuration[T Number](d T) string

func MathDiv

func MathDiv[A, B Number](a A, b B, precision ...int) float64

func Overwrite

func Overwrite(opts *SaveOptions)

func ReadCloser

func ReadCloser(read bytesFunc) io.ReadCloser

func Reader

func Reader(read bytesFunc) io.Reader

func Save

func Save(src io.Reader, filePath string, opts ...SaveOption) (err error)

func SetDataDir

func SetDataDir(path string)

func UseTempFile

func UseTempFile(opts *SaveOptions)

func WriteCloser

func WriteCloser(write bytesFunc) io.WriteCloser

func Writer

func Writer(write bytesFunc) io.Writer

Types

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type ProgressHook

type ProgressHook func(cur, total int64)

type SaveHook

type SaveHook func() error

type SaveOption

type SaveOption func(*SaveOptions)

func AfterSave

func AfterSave(after SaveHook) SaveOption

func BeforeSave

func BeforeSave(before SaveHook) SaveOption

func ConsoleProgress

func ConsoleProgress() SaveOption

func Mode

func Mode(mode fs.FileMode) SaveOption

func Progress

func Progress(report ProgressHook) SaveOption

func TotalBytes

func TotalBytes(total int64) SaveOption

type SaveOptions

type SaveOptions struct {
	Overwrite   bool         `json:"overwrite,omitempty"`
	Mode        fs.FileMode  `json:"mode,omitempty"`
	TotalBytes  int64        `json:"total_bytes,omitempty"`
	UseTempFile bool         `json:"use_temp_file,omitempty"`
	Progress    ProgressHook `json:"-"`
	BeforeSave  []SaveHook   `json:"-"`
	AfterSave   []SaveHook   `json:"-"`
}

func (*SaveOptions) With

func (options *SaveOptions) With(opts ...SaveOption) *SaveOptions

Jump to

Keyboard shortcuts

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