blobs

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 12 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 blobs stores immutable file contents by SHA-256 under <dir>/<first two hex digits>/<id> (docs/design/vault.md).

Index

Constants

This section is empty.

Variables

View Source
var ErrCorrupt = errors.New("blobs: content does not match its id")

ErrCorrupt indicates that stored content does not match its ID.

View Source
var ErrInvalidID = errors.New("blobs: invalid id")

ErrInvalidID rejects IDs that are not exactly 64 lowercase hex digits.

Functions

func ID

func ID(data []byte) string

ID returns the lowercase hex SHA-256 of data.

func IDReader

func IDReader(r io.Reader) (string, error)

IDReader returns the lowercase hex SHA-256 of everything r yields: ID for content too big to hold in memory.

Types

type Store

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

Store is a directory of immutable blobs. It is safe for concurrent use.

func New

func New(dir string) *Store

New returns a Store rooted at dir without creating any files or directories.

func (*Store) Get

func (s *Store) Get(id string) ([]byte, error)

Get reads a blob and verifies its ID, returning nil and an error matching ErrCorrupt if its content has changed. Missing blobs match fs.ErrNotExist.

func (*Store) Has

func (s *Store) Has(id string) (bool, error)

Has reports whether a blob exists; malformed IDs return ErrInvalidID.

func (*Store) IDs

func (s *Store) IDs(ctx context.Context) ([]string, error)

IDs returns all regularly stored blob IDs in ascending order, ignoring stray files. Empty and missing stores return a non-nil empty slice.

func (*Store) ModTime

func (s *Store) ModTime(id string) (time.Time, error)

ModTime returns when a blob was stored. A missing blob returns an error matching fs.ErrNotExist; a malformed ID returns ErrInvalidID.

func (*Store) Open

func (s *Store) Open(id string) (io.ReadCloser, error)

Open opens a blob without verifying its contents. A missing blob returns an error matching fs.ErrNotExist; a malformed ID returns ErrInvalidID.

func (*Store) Put

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

Put streams r into a temporary file, then atomically publishes the blob. Existing blobs are kept. Directories are created with mode 0700 and blobs with mode 0600. Cancellation before publication leaves no temporary file.

func (*Store) PutWant

func (s *Store) PutWant(ctx context.Context, r io.Reader, want string) error

PutWant is Put for content that must have the ID want, such as an upload or download named by its hash (ADR-0018): it publishes the blob only if it does, and otherwise stores nothing and returns an error matching ErrCorrupt. A malformed want returns ErrInvalidID before reading.

func (*Store) Remove

func (s *Store) Remove(id string) error

Remove deletes a blob. Missing blobs are ignored; malformed IDs return ErrInvalidID.

func (*Store) RemoveTemp

func (s *Store) RemoveTemp(before time.Time) (int, error)

RemoveTemp removes regular .put-* files directly in the store whose modification time precedes before, returning the number removed.

func (*Store) Size

func (s *Store) Size(id string) (int64, error)

Size returns a blob's size in bytes. A missing blob returns an error matching fs.ErrNotExist; a malformed ID returns ErrInvalidID.

Jump to

Keyboard shortcuts

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