blobstore

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

This package implements a simple disk-persisted content-addressed blobstore.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSuchKey signals that a blob with the given key does
	// not exist in the BlobStore.
	ErrNoSuchKey = errors.New("blobstore: no such key")

	// ErrBadKey signals that the given key is not well formed.
	ErrBadKey = errors.New("blobstore: bad key")
)

Functions

This section is empty.

Types

type BlobStore

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

BlobStore represents a simple disk-persisted content addressible blob store that uses the file system for persistence.

Blobs in the blobstore are indexed by their SHA1 hash.

The BlobStore is backed by a directory on the filesystem. This directory contains subdirectories which contain keys (SHA1 hashes). Each subdirectory is named according to the first hex-encoded byte of the keys that subdirectory contains.

For example, a file that has the content 'hello world' will have the SHA1 hash '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'. If our blobstore's backing directory is called 'blobstore', the blob with only 'hello world' in it will be stored as follows:

blobstore/2a/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed

The BlobStore is self-synchronizing, relying on the filesystem operations to ensure atomicity. Thus, accessing a single BlobStore from multiple goroutines should have no ill side effects.

func Open

func Open(path string) BlobStore

Open opens an existing BlobStore. The path parameter must point to a directory that already exists for correct operation, however, the Open function does not check that this is the case.

func (BlobStore) Get

func (bs BlobStore) Get(key string) ([]byte, error)

Get returns a byte slice containing the contents of the blob identified by key. If no such blob is found, Get returns ErrNoSuchKey.

func (BlobStore) Put

func (bs BlobStore) Put(buf []byte) (key string, err error)

Put puts the contents of blob into the BlobStore. If the blob was successfully stored, the returned key can be used to retrieve the buf from the BlobStore at a later time.

type EOFHashMismatchError

type EOFHashMismatchError struct {
	// Sum represents that was calculated during the read operation.
	Sum []byte
}

EOFHashMismatchError signals that a blobReader reached EOF, but that the calculated hash did not match the given blob key. This signals a successful read of the blob, but that the on-disk content is corrupted in some fashion.

func (EOFHashMismatchError) Error

func (hme EOFHashMismatchError) Error() string

Jump to

Keyboard shortcuts

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