cas

package
v0.0.0-...-cffa139 Latest Latest
Warning

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

Go to latest
Published: May 29, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cas implements a Content-Addressed Store.

Data stored in it will be cryptographically hashed into a Key, that can later be used to fetch the data. Storing the same data again will result in the same Key, and not take extra space.

Index

Constants

View Source
const KeySize = 64

Size of the CAS keys in bytes.

Variables

View Source
var Empty = Key{}

The Empty key is special, it denotes no data stored (potentially after discarding trailing zeroes in the data). The empty key is all zero bytes.

View Source
var Invalid = Key{newInvalidKey()}

The Invalid key is special, it denotes input to NewKey that contained to use a reserved or private key. Or, respectively, just reserved for NewKeyPrivate.

These key byte values are never marshaled anywhere, so seeing them in input is always illegal.

Functions

This section is empty.

Types

type BadKeySizeError

type BadKeySizeError struct {
	Key []byte
}

BadKeySizeError is passed to panic if NewKey is called with input that is not KeySize long.

func (*BadKeySizeError) Error

func (b *BadKeySizeError) Error() string

type Key

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

A Key that identifies data stored in the CAS. Keys are immutable.

func NewKey

func NewKey(b []byte) Key

NewKey makes a new Key with the given byte contents. If the input happens to be a reserved byte sequence, the returned key will be Invalid.

This function is intended for use when unmarshaling keys from storage.

panics with BadKeySizeError if len(b) does not match KeySize

func NewKeyPrivate

func NewKeyPrivate(b []byte) Key

NewKeyPrivate is like NewKey, but allows byte sequences in the private range. The private data can be extracted with the method Private.

panics with BadKeySize if len(b) does not match KeySize

func NewKeyPrivateNum

func NewKeyPrivateNum(num uint64) Key

NewKeyPrivateNum makes a new Key in the private range, with the given number encoded in it. The number can be extracted from the key with the method Private.

func (*Key) Bytes

func (k *Key) Bytes() []byte

Bytes returns a byte slice with the byte content of the key.

func (*Key) IsPrivate

func (k *Key) IsPrivate() bool

IsPrivate returns true if the key is private. Private keys can be used to store 64 bits of data in them, but cannot be stored persistently. See Private, NewKeyPrivate, NewKeyPrivateNum.

func (*Key) IsReserved

func (k *Key) IsReserved() bool

IsReserved returns true if the key is reserved. Caller should never use reserved keys.

func (*Key) IsSpecial

func (k *Key) IsSpecial() bool

IsSpecial returns true if the key is special. Special keys are further categorized into:

  • Empty key: test with k == Empty
  • Private keys: test with k.IsPrivate() or num, ok = k.Private()
  • Reserved keys: test with k.IsReserved(); includes the Invalid key

func (*Key) MarshalBinary

func (k *Key) MarshalBinary() (data []byte, err error)

func (*Key) Private

func (k *Key) Private() (num uint64, ok bool)

Private extracts the private data from a Key in the private range. The return value ok is false if the Key was not a private key.

func (Key) String

func (k Key) String() string

String returns a hex encoding of the key.

func (*Key) UnmarshalBinary

func (k *Key) UnmarshalBinary(b []byte) error

type NotFoundError

type NotFoundError struct {
	Type  string
	Level uint8
	Key   Key
}

NotFoundError is the type of error returned by a CAS when it cannot find the requested key.

func (NotFoundError) Error

func (n NotFoundError) Error() string

Directories

Path Synopsis
Package chunks implements low-level storage for chunks of data.
Package chunks implements low-level storage for chunks of data.
chunkutil
Package chunkutil contains helper functions only needed by chunks.Store implementations.
Package chunkutil contains helper functions only needed by chunks.Store implementations.
mock
Package mock contains chunks.Store implementation for testing.
Package mock contains chunks.Store implementation for testing.
Package flagx contains a helper type for parsing CAS keys from command line arguments.
Package flagx contains a helper type for parsing CAS keys from command line arguments.
Package wire is a generated protocol buffer package.
Package wire is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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