blob

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package blob stores object payloads as content-addressed files.

Bytes never sit in the heap in full: an upload streams from the request body through the hashers to a temp file in one pass, and a download is served from the file. Memory stays flat whatever the object's size — the property fake-gcs-server does not have, where a 2 GB file has driven RSS past 12 GB.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("blob: not found")

ErrNotFound is returned for a digest the store does not hold.

Functions

This section is empty.

Types

type Ref

type Ref struct {
	// SHA256 is the content address, lowercase hex.
	SHA256 string

	Size int64

	// CRC32C is base64 of the four big-endian checksum bytes, as GCS spells it.
	CRC32C string

	// MD5 is base64 of the digest, as GCS spells it.
	MD5 string
}

Ref describes stored content: its address, and the checksums GCS reports.

type Store

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

Store is a content-addressed blob tree rooted at a directory.

func New

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

New opens a blob tree under root, creating it if needed.

func NewTemp

func NewTemp() (*Store, error)

NewTemp opens a blob tree in a temporary directory, which Close removes.

func (*Store) Close

func (s *Store) Close() error

Close removes the tree if the store created it.

func (*Store) Delete

func (s *Store) Delete(sha256hex string) error

Delete removes content. Deleting what is not there is not an error: the caller wanted it gone.

func (*Store) Fork

func (s *Store) Fork() (*Store, error)

Fork returns a new store holding the same content, in its own directory.

The files are hardlinked, not copied: content here is immutable and addressed by its own hash, so two trees can share the bytes on disk. What they do not share is the right to delete — dropping the last reference in one store removes only that store's link, leaving the other's intact. That is the whole difficulty a shared tree has: a parent overwriting an object would otherwise pull the content out from under a fork still pointing at it.

func (*Store) Open

func (s *Store) Open(sha256hex string) (*os.File, error)

Open returns the content for a digest. The caller closes it.

func (*Store) Path

func (s *Store) Path(sha256hex string) string

Path is where a digest's content lives. Exported so a handler can hand the file to http.ServeContent, which streams and handles Range itself.

func (*Store) Put

func (s *Store) Put(ctx context.Context, r io.Reader) (Ref, error)

Put streams r into the tree and returns its Ref.

One pass: the reader is copied into the temp file and all three hashes at once, so the bytes are never read twice and never held whole.

func (*Store) Reset

func (s *Store) Reset() error

Reset removes every blob, leaving the tree usable.

func (*Store) Root

func (s *Store) Root() string

Root is the directory the tree lives under.

Jump to

Keyboard shortcuts

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