Documentation
¶
Overview ¶
Package blobs stores immutable file contents by SHA-256 under <dir>/<first two hex digits>/<id> (docs/design/vault.md).
Index ¶
- Variables
- func ID(data []byte) string
- func IDReader(r io.Reader) (string, error)
- type Store
- func (s *Store) Get(id string) ([]byte, error)
- func (s *Store) Has(id string) (bool, error)
- func (s *Store) IDs(ctx context.Context) ([]string, error)
- func (s *Store) ModTime(id string) (time.Time, error)
- func (s *Store) Open(id string) (io.ReadCloser, error)
- func (s *Store) Put(ctx context.Context, r io.Reader) (string, error)
- func (s *Store) PutWant(ctx context.Context, r io.Reader, want string) error
- func (s *Store) Remove(id string) error
- func (s *Store) RemoveTemp(before time.Time) (int, error)
- func (s *Store) Size(id string) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var ErrCorrupt = errors.New("blobs: content does not match its id")
ErrCorrupt indicates that stored content does not match its ID.
var ErrInvalidID = errors.New("blobs: invalid id")
ErrInvalidID rejects IDs that are not exactly 64 lowercase hex digits.
Functions ¶
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 (*Store) Get ¶
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) IDs ¶
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 ¶
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 ¶
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 ¶
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 ¶
Remove deletes a blob. Missing blobs are ignored; malformed IDs return ErrInvalidID.
func (*Store) RemoveTemp ¶
RemoveTemp removes regular .put-* files directly in the store whose modification time precedes before, returning the number removed.