Documentation
¶
Overview ¶
Package cafs provides a content-addressable store with OCI registry sync and merkle tree semantics.
CAFS stores blobs by content digest and indexes them by string keys. Keys cannot be empty, exceed 1024 bytes, start with "_", or contain ".." or null bytes. Directory hashes are computed on-demand from the flat index, enabling instant comparison of subtrees without storing tree objects.
Basic usage (local only):
fs, _ := cafs.Open("myproject:main")
// Store content by key
fs.Put("src/main.go", data)
// Store with metadata
fs.Put("src/util.go", data, cafs.WithMeta(cafs.FileMeta{Mode: 0644}))
// Retrieve content
data, _ := fs.Get("src/main.go")
// Get entry info
info, ok := fs.Stat("src/main.go")
fmt.Println(info.Digest, info.Size)
// Check existence and count
if fs.Exists("src/main.go") { ... }
fmt.Println(fs.Len(), "entries")
// Compare directories
if fs.Hash("src/") != previousHash {
// src/ changed
}
// Maintenance
stats := fs.Stats() // entry count, blob count, total size
removed, _ := fs.GC() // remove unreferenced blobs
fs.Clear() // remove all entries
With remote sync:
fs, _ := cafs.Open("myproject:main", cafs.WithRemote("ttl.sh/myorg/cache"))
fs.Push(ctx)
fs.Pull(ctx)
fmt.Println("remote:", fs.Ref())
Index ¶
- Constants
- Variables
- type Authenticator
- type CAS
- func (s *CAS) Clear()
- func (s *CAS) Close() error
- func (s *CAS) Delete(key string)
- func (s *CAS) Dirty() bool
- func (s *CAS) Exists(key string) bool
- func (s *CAS) GC() (int, error)
- func (s *CAS) Get(key string) ([]byte, error)
- func (s *CAS) Hash(prefix string) Digest
- func (s *CAS) Len() int
- func (s *CAS) List(prefix string) iter.Seq2[string, Info]
- func (s *CAS) Path(digest Digest) string
- func (s *CAS) Pull(ctx context.Context) error
- func (s *CAS) Push(ctx context.Context, tags ...string) error
- func (s *CAS) Put(key string, data []byte, opts ...Option) error
- func (s *CAS) Ref() string
- func (s *CAS) Root() Digest
- func (s *CAS) Stat(key string) (Info, bool)
- func (s *CAS) Stats() Stats
- func (s *CAS) Sync() error
- type Digest
- type FileMeta
- type Info
- type OpenOption
- type OpenOptions
- type Option
- type Stats
- type Store
Constants ¶
const ( AutoPullNever = "never" AutoPullAlways = "always" AutoPullMissing = "missing" )
AutoPull modes
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator = remote.Authenticator
Authenticator provides credentials for remote registries.
type CAS ¶
type CAS struct {
// contains filtered or unexported fields
}
CAS is the main content-addressable storage implementation.
type FileMeta ¶
type FileMeta struct {
Mode os.FileMode `json:"mode,omitempty" mapstructure:"mode"`
ModTime time.Time `json:"mtime,omitempty" mapstructure:"mtime"`
}
FileMeta provides common file system metadata.
func FileMetaFrom ¶
FileMetaFrom creates FileMeta from os.FileInfo.
type Info ¶
type Info struct {
Digest Digest // content hash
Size int64 // content size
Meta any // optional user-defined metadata
}
Info represents metadata about a stored entry.
func (Info) DecodeMeta ¶
DecodeMeta decodes the metadata into a typed struct using mapstructure.
type OpenOption ¶
type OpenOption func(*OpenOptions)
OpenOption is a functional option for configuring Open.
func WithAuth ¶
func WithAuth(auth Authenticator) OpenOption
WithAuth sets custom authentication for remote operations.
func WithAutoPull ¶
func WithAutoPull(mode string) OpenOption
WithAutoPull enables automatic pulling from remote on Open.
func WithCacheDir ¶
func WithCacheDir(dir string) OpenOption
WithCacheDir sets the local cache directory.
func WithConcurrency ¶
func WithConcurrency(n int) OpenOption
WithConcurrency sets the number of parallel operations for push/pull.
func WithRemote ¶
func WithRemote(imageRef string) OpenOption
WithRemote sets the OCI registry image ref for push/pull operations.
type OpenOptions ¶
type OpenOptions struct {
CacheDir string
Remote string // OCI image ref for push/pull (optional)
Auth Authenticator
AutoPull string
Concurrency int
}
OpenOptions configures a CAS store.
type Stats ¶
type Stats struct {
Entries int // number of user entries
Blobs int // number of unique blobs on disk
TotalSize int64 // total size of all blobs
}
Stats contains storage statistics.
type Store ¶
type Store interface {
// Core operations
Put(key string, data []byte, opts ...Option) error
Get(key string) ([]byte, error)
Stat(key string) (Info, bool)
Delete(key string)
Clear()
// Iteration
List(prefix string) iter.Seq2[string, Info]
// Tree hash
Hash(prefix string) Digest
// Sync
Sync() error
Push(ctx context.Context, tags ...string) error
Pull(ctx context.Context) error
Close() error
// Status
Root() Digest
Dirty() bool
Len() int
Ref() string
Exists(key string) bool
Stats() Stats
// Maintenance
GC() (removed int, err error)
// Advanced
Path(digest Digest) string
}
Store provides content-addressed storage with OCI sync.