cas

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cas stores immutable blobs by their SHA-256 digest.

Fold pointers make graph reachability explicit. Garbage collection remains intentionally out of scope: immutable overflow is kept until a later pass can prove that no journal event refers to it.

Index

Constants

View Source
const Scheme = "cas://"

Scheme prefixes a durable attachment reference.

Variables

View Source
var (
	// ErrInvalidRef means a reference is not a hexadecimal SHA-256 digest.
	ErrInvalidRef = errors.New("invalid cas ref")
	// ErrContentMismatch means stored bytes no longer hash to their reference.
	ErrContentMismatch = errors.New("cas content does not match ref")
)

Functions

func Reference

func Reference(ref Ref, originalPath string) string

A reference is written as cas://<digest>/<the path the user attached>, and the shape is deliberate. The digest is the durable half: the bytes live in the store under it, so a job retried next week reads exactly what was attached even if the person has since moved, renamed, or deleted their copy. The path is the honest half: it is what the attachment is called, where it came from, and what every reader — a chip in the composer, the compiler's list of attached documents, filepath.Ext — needs to see. Keeping the path at the tail means those readers keep working on a reference unchanged, and a reference read by something that knows nothing about this format still says out loud which file it means.

func SourcePath

func SourcePath(reference string) string

SourcePath is what a reader that only understands paths should look at: the file the person attached. It is unchanged for anything that is already a path.

Types

type Ref

type Ref string

Ref is the lowercase hexadecimal SHA-256 digest of a blob.

func DigestBytes

func DigestBytes(data []byte) Ref

DigestBytes names content without storing it, for callers that need the same identity the store uses — a staged copy's suffix, a duplicate check.

func ParseReference

func ParseReference(reference string) (ref Ref, originalPath string, ok bool)

ParseReference splits a durable reference into its digest and the path it was made from. Anything that is not a reference comes back unchanged as a path, so a caller can hold both kinds in one list.

func (Ref) String

func (r Ref) String() string

type Store

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

Store is a content-addressed collection of immutable blobs.

func New

func New(root string) (*Store, error)

New opens a store rooted at root, creating it when necessary.

func (*Store) Get

func (s *Store) Get(ref Ref) (io.ReadCloser, error)

Get opens a stored blob for reading.

func (*Store) Path

func (s *Store) Path(ref Ref) (string, error)

Path returns the absolute on-disk path for a reference.

func (*Store) Put

func (s *Store) Put(reader io.Reader) (Ref, error)

Put streams a blob into the store and returns its content digest.

func (*Store) PutBytes

func (s *Store) PutBytes(data []byte) (Ref, error)

PutBytes stores data without requiring the caller to construct a reader.

func (*Store) PutFile

func (s *Store) PutFile(path string) (Ref, error)

PutFile streams an existing file into the store.

func (*Store) Stat

func (s *Store) Stat(ref Ref) (size int64, exists bool, err error)

Stat reports a blob's size and whether it exists.

func (*Store) Verify

func (s *Store) Verify(ref Ref) error

Verify checks that stored content still hashes to ref.

Jump to

Keyboard shortcuts

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