fs

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

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

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

New creates a new filesystem storage backend.

func (*Storage) FS added in v0.8.0

func (s *Storage) FS() (fs.FS, error)

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

func (s *Storage) GetResourceSize(key string) uint

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

func (s *Storage) GetResourceURL(key string) string

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

func (s *Storage) GetSnapshotSize(key string) uint

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

func (s *Storage) GetStreamSize(key string) uint

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

func (s *Storage) GetStreamURL(key string) string

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

func (s *Storage) SaveResource(ext string, resource io.Reader) (string, error)

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

func (s *Storage) SaveSnapshot(key string, snapshot []byte) error

SaveSnapshot saves a snapshot to disk with gzip compression. Creates the necessary directory structure if it doesn't exist.

func (*Storage) SaveStream added in v0.9.0

func (s *Storage) SaveStream(ext string, resource io.Reader) (string, error)

SaveStream saves a streamable content to disk. Creates the necessary directory structure if it doesn't exist.

Jump to

Keyboard shortcuts

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