blob

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package blob stores content-addressed objects: file contents and trees.

Objects are immutable. Put returns the hash of the object, and storing the same bytes twice is a no-op. Every read is verified against its hash, so a corrupted store fails loudly instead of returning wrong content.

Index

Constants

This section is empty.

Variables

View Source
var ErrCorrupt = errors.New("object corrupt")

ErrCorrupt is returned when stored bytes do not match their hash.

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

ErrNotFound is returned when an object is not in the store.

Functions

func GetKind

func GetKind(ctx context.Context, s Store, want hash.Kind, h hash.Hash) ([]byte, error)

GetKind is Get that also checks the object has the expected kind.

Types

type Disk

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

Disk stores objects as files under a root directory, fanned out by the first two bytes of the hash: root/9f/1c/9f1c....

func NewDisk

func NewDisk(root string) (*Disk, error)

NewDisk opens (and creates) a disk store at root.

func (*Disk) Get

func (d *Disk) Get(ctx context.Context, h hash.Hash) (hash.Kind, []byte, error)

Get implements Store.

func (*Disk) Has

func (d *Disk) Has(ctx context.Context, h hash.Hash) (bool, error)

Has implements Store.

func (*Disk) Put

func (d *Disk) Put(ctx context.Context, kind hash.Kind, data []byte) (hash.Hash, error)

Put implements Store.

type Mem

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

Mem is an in-memory Store for tests and short-lived work.

func NewMem

func NewMem() *Mem

NewMem returns an empty in-memory store.

func (*Mem) Get

func (m *Mem) Get(_ context.Context, h hash.Hash) (hash.Kind, []byte, error)

Get implements Store.

func (*Mem) Has

func (m *Mem) Has(_ context.Context, h hash.Hash) (bool, error)

Has implements Store.

func (*Mem) Len

func (m *Mem) Len() int

Len returns the number of stored objects.

func (*Mem) Put

func (m *Mem) Put(_ context.Context, kind hash.Kind, data []byte) (hash.Hash, error)

Put implements Store.

type Store

type Store interface {
	// Put stores data under the hash of kind and data.
	Put(ctx context.Context, kind hash.Kind, data []byte) (hash.Hash, error)
	// Get returns the object and its kind.
	Get(ctx context.Context, h hash.Hash) (hash.Kind, []byte, error)
	// Has reports whether the object exists.
	Has(ctx context.Context, h hash.Hash) (bool, error)
}

Store is a content-addressed object store.

Jump to

Keyboard shortcuts

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