Documentation
¶
Overview ¶
Package fs implements filesystem-based storage for Omnom snapshots and resources.
This package provides the Storage type which implements the storage.Storage interface using the local filesystem. All content is stored in a configurable base directory with the following structure:
<base_dir>/
snapshots/
<2-char-prefix>/
<hash>.html.gz
resources/
<2-char-prefix>/
<hash><extension>
All files are compressed with gzip before being written to disk. The two-character prefix directories (based on the first two characters of the content hash) help distribute files across multiple directories to avoid filesystem performance issues.
Example usage:
storage, err := fs.New(config.StorageFilesystem{
RootDir: "./data",
})
if err != nil {
log.Fatal(err)
}
// Storage implements the storage.Storage interface
err = storage.SaveSnapshot(key, content)
Index ¶
- type Storage
- func (s *Storage) FS() (fs.FS, error)
- func (s *Storage) GetResource(key string) io.ReadCloser
- func (s *Storage) GetResourceSize(key string) uint
- func (s *Storage) GetResourceURL(key string) string
- func (s *Storage) GetSnapshot(key string) io.ReadCloser
- func (s *Storage) GetSnapshotSize(key string) uint
- func (s *Storage) GetStream(key string) io.ReadCloser
- func (s *Storage) GetStreamSize(key string) uint
- func (s *Storage) GetStreamURL(key string) string
- func (s *Storage) SaveResource(ext string, resource io.Reader) (string, error)
- func (s *Storage) SaveSnapshot(key string, snapshot []byte) error
- func (s *Storage) SaveStream(ext string, resource io.Reader) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Storage ¶ added in v0.8.0
type Storage struct {
// contains filtered or unexported fields
}
Storage implements filesystem-based storage for snapshots and resources.
func New ¶
func New(cfg config.StorageFilesystem) (*Storage, error)
New creates a new filesystem storage backend.
func (*Storage) FS ¶ added in v0.8.0
FS returns the storage directory as an io/fs.FS for filesystem operations.
func (*Storage) GetResource ¶ added in v0.8.0
func (s *Storage) GetResource(key string) io.ReadCloser
GetResource retrieves a gzip-compressed resource file by its key. Returns nil if the resource doesn't exist or cannot be opened.
func (*Storage) GetResourceSize ¶ added in v0.8.0
GetResourceSize returns the size in bytes of a stored resource file. Returns 0 if the resource doesn't exist or an error occurs.
func (*Storage) GetResourceURL ¶ added in v0.8.0
GetResourceURL constructs the HTTP URL path for accessing a resource. The URL path includes a two-character prefix directory for distribution.
func (*Storage) GetSnapshot ¶ added in v0.8.0
func (s *Storage) GetSnapshot(key string) io.ReadCloser
GetSnapshot retrieves a snapshot file by its key. Returns nil if the snapshot doesn't exist or cannot be opened.
func (*Storage) GetSnapshotSize ¶ added in v0.8.0
GetSnapshotSize returns the size in bytes of a stored snapshot file. Returns 0 if the snapshot doesn't exist or an error occurs.
func (*Storage) GetStream ¶ added in v0.9.0
func (s *Storage) GetStream(key string) io.ReadCloser
GetStream retrieves a streamable content file by its key. Returns nil if the resource doesn't exist or cannot be opened.
func (*Storage) GetStreamSize ¶ added in v0.9.0
GetStreamSize returns the size in bytes of a stored streamable file. Returns 0 if the resource doesn't exist or an error occurs.
func (*Storage) GetStreamURL ¶ added in v0.9.0
GetStreamURL constructs the HTTP URL path for accessing a streamable content. The URL path includes a two-character prefix directory for distribution.
func (*Storage) SaveResource ¶ added in v0.8.0
SaveResource saves a resource to disk with gzip compression. Creates the necessary directory structure if it doesn't exist.
func (*Storage) SaveSnapshot ¶ added in v0.8.0
SaveSnapshot saves a snapshot to disk with gzip compression. Creates the necessary directory structure if it doesn't exist.