blob

package
v0.0.0-...-01ee8fb Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package blob contains types related to storage of content-addressed blobs. It is an implementation detail; you should not use it directly.

Index

Constants

View Source
const ScoreLength = 20

A Score is the identifier for a blob previously stored by a blob store. It consists of a 20-byte SHA-1 hash of the blob's contents, so that with high probability two blobs have the same contents if and only if they have the same score.

Variables

This section is empty.

Functions

func ListBlobObjects

func ListBlobObjects(
	ctx context.Context,
	bucket gcs.Bucket,
	namePrefix string,
	objects chan<- *gcs.Object) (err error)

Write object records for all of the blob objects in the supplied bucket into the given channel, without closing it. The order of records is undefined. The caller will likely want to call ParseObjectRecord for each record.

func ListScores

func ListScores(
	ctx context.Context,
	bucket gcs.Bucket,
	namePrefix string,
	scores chan<- Score) (err error)

Feed the output of ListBlobObjects into ParseObjectRecord, passing on the scores to the supplied channel without closing it.

Types

type SaveRequest

type SaveRequest struct {
	// The blob data to be stored.
	Blob []byte
	// contains filtered or unexported fields
}

type Score

type Score [ScoreLength]byte

func ComputeScore

func ComputeScore(b []byte) (s Score)

Compute the score for the supplied blob. This is primarily intended for use by blob store implementations; most users should obtain scores through calls to a blob store's Store method.

func ParseHexScore

func ParseHexScore(hexScore string) (s Score, err error)

Parse the output of Score.Hex.

func ParseObjectRecord

func ParseObjectRecord(
	o *gcs.Object,
	namePrefix string) (score Score, err error)

Parse and verify the internal consistency of the supplied object record in the same manner that a gcsStore configured with the supplied object name prefix would. Return the score of the blob that the object contains.

func (Score) Hex

func (s Score) Hex() string

Return a fixed-width hex version of the score's hash, suitable for using e.g. as a filename.

type Store

type Store interface {
	// Store a blob, returning a score with which it can later be retrieved.
	Save(
		ctx context.Context,
		req *SaveRequest) (s Score, err error)

	// Load a previously-stored blob.
	Load(ctx context.Context, s Score) (blob []byte, err error)
}

A Store knows how to save blobs for later retrieval.

func NewCheckingStore

func NewCheckingStore(wrapped Store) Store

Return a blob store that wraps the supplied one, confirming that the blob contents it loads are correct, guarding against silent data corruption.

func NewEncryptingStore

func NewEncryptingStore(crypter crypto.Crypter, wrapped Store) Store

Return a blob store that wraps the supplied one, encrypting and decrypting data as it passes through. The supplied crypter should have deterministic output.

func NewExistingScoresStore

func NewExistingScoresStore(
	existingScores util.StringSet,
	wrapped Store) (store Store)

Create a blob store that wraps another, responding immediately to calls to Store for content that already exists in the wrapped blob store. For calls that are passed on, this store will fill in SaveRequest.score.

existingScores must initially be a subset of the scores contained by the wrapped store, in hex form. It will be updated upon successful calls to wrapped.Store.

func NewGCSStore

func NewGCSStore(
	bucket gcs.Bucket,
	prefix string) (store Store)

Return a blob store that stores blobs in the supplied GCS bucket. GCS object names look like:

<prefix><score>

where <score> is the result of calling Score.Hex.

The blob store trusts that it has full ownership of this portion of the bucket's namespace -- if a score name exists, then it points to the correct data.

Awkward interface: the resulting store requires SaveRequest.score fields to be filled in by the caller. This is accomplished by ensuring that it is wrapped by a store created with NewEncryptingStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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