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 ¶
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.
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 ¶
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 ¶
Parse the output of Score.Hex.
func ParseObjectRecord ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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.