storage

package module
v0.0.0-...-dbbdc9a Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInput = errors.New("invalid input")

Functions

func CopyContents

func CopyContents(pathHandle, contents any) error

CopyContents copies each field of contents to its corresponding field of pathHandle.

pathHandle and contents must be flat structs and must only contain exported afero.Fs, fs.FS fields respectively.

type pathHandle struct {
	RuntimeEnvFiles afero.Fs
}

type Contents struct {
	RuntimeEnvFiles fs.FS
}

composePath, err := composeloader.CopyContents(
	pathHandle,
	Contents{
		RuntimeEnvFiles: fstest.MapFS{
			"foo.env": &fstest.MapFile{
				Data:    []byte{},
				Mode:    0o664,
				ModTime: time.Now(),
			},
			"bar.env": &fstest.MapFile{
				Data:    []byte{},
				Mode:    0o664,
				ModTime: time.Now(),
			},
		},
	},
)

func PathModifierAppendIndex

func PathModifierAppendIndex(path string, i int) string

PathModifierAppendIndex appends path with "_" + i. i will be padded with "0" to be 3 digits. If i > 999 or i < -99, number will be 4 digits or 3 digits with minus sign.

PathModifierAppendIndex removes filepath.Separator from tail if path is suffixed with it.

func PrepareHandle

func PrepareHandle[S, H any](base afero.Fs, pathSet S, initialContents any) (H, error)

func ValidateCopyContentsInput

func ValidateCopyContentsInput(pathHandle, dirContents any, allowNilField bool) error

func ValidatePrepareInput

func ValidatePrepareInput(pathSet, pathHandle any) error

func WriteSplitting

func WriteSplitting(
	fsys afero.Fs,
	opt fsutil.SafeWriteOption,
	path string,
	perm fs.FileMode,
	r io.Reader,
	size uint,
	pathModifier func(path string, i int) string,
	trapper func(path string, r io.Reader) io.Reader,
) ([]string, error)

Types

type ReaderSplitter

type ReaderSplitter interface {
	// Size returns limit size.
	// io.Reader returned from Next reads up to this size.
	// The last reader may reads less than Size.
	Size() int
	// Next returns size limited readers.
	// If ok is true, r is non nil and r reads up to given size.
	// Next and r.Read are not goroutine safe.
	// Calling Next before r is fully consumed causes an undefined behavior.
	Next() (r io.Reader, ok bool)
}

ReadSplitter returns splitted readers sequentially.

func SplitReader

func SplitReader(r io.Reader, size uint) ReaderSplitter

SplitReader returns ReaderSplitter splitting at size. It will panic if size is 0.

type SafeWriter

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

func NewSafeWriter

func NewSafeWriter(fsys afero.Fs, option fsutil.SafeWriteOption) *SafeWriter

func (*SafeWriter) CleanTmp

func (s *SafeWriter) CleanTmp() error

func (*SafeWriter) Fsys

func (s *SafeWriter) Fsys() afero.Fs

func (*SafeWriter) Write

func (s *SafeWriter) Write(
	path string,
	perm fs.FileMode,
	r io.Reader,
	postProcesses ...fsutil.SafeWritePostProcess,
) error

func (*SafeWriter) WriteFs

func (s *SafeWriter) WriteFs(
	dir string,
	perm fs.FileMode,
	src fs.FS,
	postProcesses ...fsutil.SafeWritePostProcess,
) error

type SplittedFileHash

type SplittedFileHash struct {
	Path     string
	Size     int
	HashSum  string
	HashAlgo string
}

type SplittedFileMetadata

type SplittedFileMetadata struct {
	Total    SplittedFileHash
	Splitted []SplittedFileHash
}

type SplittingStorage

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

func NewSplittingStorage

func NewSplittingStorage(
	fileFsys *SafeWriter,
	metadataFsys *SafeWriter,
	splitSize uint,
	pathModifier func(s string, i int) string,
	safeWriteOption fsutil.SafeWriteOption,
) *SplittingStorage

func (*SplittingStorage) Read

func (s *SplittingStorage) Read(path string) (r io.ReadCloser, size int, err error)

func (*SplittingStorage) Write

func (s *SplittingStorage) Write(path string, perm fs.FileMode, r io.Reader) ([]string, error)

Directories

Path Synopsis
cmd
The code is generated by github.com/ngicks/musicbox/composeloader/cmd/gentypes DO NOT EDIT.
The code is generated by github.com/ngicks/musicbox/composeloader/cmd/gentypes DO NOT EDIT.

Jump to

Keyboard shortcuts

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