local

package
v2.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package local provides local filesystem-based storage implementation.

Index

Constants

View Source
const (

	// DefaultMaxFileSize is the default maximum file size (50 MB).
	DefaultMaxFileSize = 50 * 1024 * 1024
)

Variables

View Source
var ErrFileTooLarge = fmt.Errorf("file size exceeds maximum allowed size")

ErrFileTooLarge is returned when data exceeds the configured MaxFileSize.

Functions

This section is empty.

Types

type FileStore

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

FileStore implements MediaStorageService using local filesystem storage.

func NewFileStore

func NewFileStore(config FileStoreConfig, opts ...FileStoreOption) (*FileStore, error)

NewFileStore creates a new local filesystem storage backend. Optional FileStoreOption values can be passed to override config fields.

func (*FileStore) DeleteMedia

func (fs *FileStore) DeleteMedia(ctx context.Context, reference storage.Reference) error

DeleteMedia implements MediaStorageService.DeleteMedia

func (*FileStore) Flush

func (fs *FileStore) Flush() error

Flush persists any pending dedup index changes to disk. Call this periodically or before shutting down to ensure the index is saved.

func (*FileStore) GetURL

func (fs *FileStore) GetURL(ctx context.Context, reference storage.Reference, expiry time.Duration) (string, error)

GetURL implements MediaStorageService.GetURL

func (*FileStore) RetrieveMedia

func (fs *FileStore) RetrieveMedia(ctx context.Context, reference storage.Reference) (*types.MediaContent, error)

RetrieveMedia implements MediaStorageService.RetrieveMedia

func (*FileStore) StoreMedia

func (fs *FileStore) StoreMedia(
	ctx context.Context, content *types.MediaContent, metadata *storage.MediaMetadata,
) (storage.Reference, error)

StoreMedia implements MediaStorageService.StoreMedia

type FileStoreConfig

type FileStoreConfig struct {
	// BaseDir is the root directory for media storage
	BaseDir string

	// Organization determines how files are organized in directories
	Organization storage.OrganizationMode

	// EnableDeduplication enables content-based deduplication using SHA-256 hashing
	EnableDeduplication bool

	// DefaultPolicy is the default retention policy to apply to new media
	DefaultPolicy string

	// MaxFileSize is the maximum allowed file size in bytes.
	// If zero, DefaultMaxFileSize (50 MB) is used.
	// Set to a negative value to disable the size limit.
	MaxFileSize int64

	// PolicyHandler, when set, is asked to apply each media item's retention
	// policy (its PolicyName, or DefaultPolicy when that is empty) before the
	// item is written. If it returns an error, StoreMedia fails and nothing is
	// written. If it also implements storage.MediaPolicyTracker, each item is
	// passed to TrackMedia once its metadata file is written. If it implements
	// storage.MediaWriteGuard, each item's files are written and tracked
	// between BeginMediaWrite and the end of the write. When nil, policy
	// names are stored without being checked.
	PolicyHandler storage.MediaPolicyHandler
}

FileStoreConfig configures the local filesystem storage backend.

type FileStoreOption

type FileStoreOption func(*FileStoreConfig)

FileStoreOption is a functional option for configuring a FileStore.

func WithMaxFileSize

func WithMaxFileSize(size int64) FileStoreOption

WithMaxFileSize returns an option that sets the maximum file size in bytes. Set to a negative value to disable the size limit.

func WithPolicyHandler added in v2.17.0

func WithPolicyHandler(h storage.MediaPolicyHandler) FileStoreOption

WithPolicyHandler returns an option that sets the PolicyHandler that applies retention policies to stored media.

Jump to

Keyboard shortcuts

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