local

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPrefixSize is the default path prefix size.
	DefaultPrefixSize = 2
	// DefaultTargetFileMode is the default file mode when storing assets.
	DefaultTargetFileMode = 0644
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Filestore

type Filestore struct {
	TargetFileMode os.FileMode
	PrefixSize     int
	// contains filtered or unexported fields
}

Filestore is a file store that stores files on a local filesystem.

func NewFilestore

func NewFilestore(tmpPath, assetsPath string) (*Filestore, error)

NewFilestore creates a new file store operating on a (local) filesystem.

The assetsPath is the path to a directory where the assets will be stored. The tmpPath is the path to a directory where temporary files will be stored. It should be on the same filesystem as assetsPath to support atomic renames.

func (*Filestore) Exists added in v0.3.0

func (f *Filestore) Exists(ctx context.Context, hash string) (bool, error)

func (*Filestore) Fetch

func (f *Filestore) Fetch(ctx context.Context, hash string) (io.ReadCloser, error)

Fetch returns a reader to the file with the given hash. If the file does not exist, ErrNotExist is returned.

func (*Filestore) ImgproxyURLSource

func (f *Filestore) ImgproxyURLSource(hash string) (string, error)

ImgproxyURLSource gets a source URL to a local file for imgproxy.

func (*Filestore) Iterate

func (f *Filestore) Iterate(ctx context.Context, maxBatch int, callback func(hashes []string) error) error

Iterate over all files in the store with a batch size of maxBatch.

func (*Filestore) Remove

func (f *Filestore) Remove(ctx context.Context, hash string) error

Remove a file from the store with the given hash.

func (*Filestore) Size

func (f *Filestore) Size(ctx context.Context, hash string) (int64, error)

Size returns the size of the file with the given hash.

func (*Filestore) Store

func (f *Filestore) Store(ctx context.Context, r io.Reader) (hash string, err error)

Store stores the content of the reader in a local file. The content is first stored in a temporary file to compute a consistent hash (SHA256) and then the file is renamed to the hash in the assets path.

func (*Filestore) StoreHashed added in v0.3.0

func (f *Filestore) StoreHashed(ctx context.Context, r io.Reader, hash string) error

Jump to

Keyboard shortcuts

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