store

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package store provides content-addressable storage implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CAFS

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

CAFS implements content-addressable file storage. Content is stored in a sharded directory structure based on hash.

func NewCAFS

func NewCAFS(b backend.Backend, opts ...CAFSOption) *CAFS

NewCAFS creates a new content-addressable file store.

func (*CAFS) Delete

func (c *CAFS) Delete(ctx context.Context, h contentcache.Hash) error

Delete removes content by its hash.

func (*CAFS) Get

func (c *CAFS) Get(ctx context.Context, h contentcache.Hash) (io.ReadCloser, error)

Get retrieves content by its hash.

func (*CAFS) GetBytes

func (c *CAFS) GetBytes(ctx context.Context, h contentcache.Hash) ([]byte, error)

GetBytes is a convenience method for retrieving content as bytes.

func (*CAFS) GetFramed added in v1.2.0

GetFramed retrieves content with its headers.

func (*CAFS) Has

func (c *CAFS) Has(ctx context.Context, h contentcache.Hash) (bool, error)

Has checks if content with the given hash exists.

func (*CAFS) List

func (c *CAFS) List(ctx context.Context) ([]contentcache.Hash, error)

List returns all hashes in the store.

func (*CAFS) Put

func (c *CAFS) Put(ctx context.Context, r io.Reader) (contentcache.Hash, error)

Put stores content and returns its hash.

func (*CAFS) PutBytes

func (c *CAFS) PutBytes(ctx context.Context, data []byte) (contentcache.Hash, error)

PutBytes is a convenience method for storing bytes.

func (*CAFS) PutFramed added in v1.2.0

func (c *CAFS) PutFramed(ctx context.Context, header *backend.BlobHeader, body io.Reader) (contentcache.Hash, error)

PutFramed stores content with headers and returns its hash.

func (*CAFS) PutWithResult

func (c *CAFS) PutWithResult(ctx context.Context, r io.Reader) (*PutResult, error)

PutWithResult stores content and returns detailed information. Uses a temp file to avoid memory exhaustion for large content.

func (*CAFS) Size

func (c *CAFS) Size(ctx context.Context, h contentcache.Hash) (int64, error)

Size returns the size of content with the given hash.

type CAFSOption

type CAFSOption func(*CAFS)

CAFSOption configures a CAFS instance.

func WithMetaDB added in v1.2.0

func WithMetaDB(db metadb.MetaDB) CAFSOption

WithMetaDB sets a MetaDB for blob tracking.

func WithMetadataTracker

func WithMetadataTracker(tracker MetadataTracker) CAFSOption

WithMetadataTracker sets a metadata tracker for expiration support.

type ExtendedStore

type ExtendedStore interface {
	Store

	// PutWithResult stores content and returns detailed information.
	PutWithResult(ctx context.Context, r io.Reader) (*PutResult, error)

	// List returns all hashes in the store.
	// This may be expensive for large stores.
	List(ctx context.Context) ([]contentcache.Hash, error)
}

ExtendedStore provides additional operations beyond the basic Store.

type MetadataTracker

type MetadataTracker interface {
	// Create records metadata for a new blob.
	Create(ctx context.Context, hash contentcache.Hash, size int64) error
	// Touch updates the last access time for a blob.
	Touch(ctx context.Context, hash contentcache.Hash) error
	// Delete removes metadata for a blob.
	Delete(ctx context.Context, hash contentcache.Hash) error
}

MetadataTracker tracks blob metadata for expiration.

type PutResult

type PutResult struct {
	Hash   contentcache.Hash
	Size   int64
	Exists bool // true if the content already existed
}

PutResult contains information about a Put operation.

type Store

type Store interface {
	// Put stores content and returns its hash.
	// If the content already exists (same hash), this is a no-op.
	Put(ctx context.Context, r io.Reader) (contentcache.Hash, error)

	// Get retrieves content by its hash.
	// Returns ErrNotFound if the hash does not exist.
	// The caller must close the returned ReadCloser.
	Get(ctx context.Context, h contentcache.Hash) (io.ReadCloser, error)

	// Has checks if content with the given hash exists.
	Has(ctx context.Context, h contentcache.Hash) (bool, error)

	// Delete removes content by its hash.
	// Returns nil if the content does not exist (idempotent).
	Delete(ctx context.Context, h contentcache.Hash) error

	// Size returns the size of content with the given hash.
	// Returns ErrNotFound if the hash does not exist.
	Size(ctx context.Context, h contentcache.Hash) (int64, error)
}

Store provides content-addressable storage operations. Content is stored by its BLAKE3 hash, ensuring deduplication.

Directories

Path Synopsis
Package gc provides garbage collection for the content cache.
Package gc provides garbage collection for the content cache.
Package metadb provides metadata storage using bbolt for the content cache.
Package metadb provides metadata storage using bbolt for the content cache.

Jump to

Keyboard shortcuts

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