Documentation ¶
Overview ¶
Package blob defines types to refer to and retrieve low-level Camlistore blobs.
Index ¶
- Constants
- func NewHash() hash.Hash
- func ValidRefString(s string) bool
- type Blob
- type ByRef
- type ChanPeeker
- type DirFetcher
- type MemoryStore
- type Ref
- func (r Ref) Digest() string
- func (r Ref) DigestPrefix(digits int) string
- func (r Ref) DomID() string
- func (r Ref) Hash() hash.Hash
- func (r Ref) HashMatches(h hash.Hash) bool
- func (r Ref) HashName() string
- func (r Ref) IsSupported() bool
- func (r Ref) Less(o Ref) bool
- func (r Ref) MarshalBinary() (data []byte, err error)
- func (r Ref) MarshalJSON() ([]byte, error)
- func (r Ref) String() string
- func (r Ref) Sum32() uint32
- func (r Ref) Sum64() uint64
- func (r *Ref) UnmarshalBinary(data []byte) error
- func (r *Ref) UnmarshalJSON(d []byte) error
- func (r Ref) Valid() bool
- type SeekFetcher
- type SeekTester
- type SizedByRef
- type SizedRef
- type StreamingFetcher
Constants ¶
const Pattern = `\b([a-z][a-z0-9]*)-([a-f0-9]+)\b`
Pattern is the regular expression which matches a blobref. It does not contain ^ or $.
Variables ¶
This section is empty.
Functions ¶
func NewHash ¶
NewHash returns a new hash.Hash of the currently recommended hash type. Currently this is just SHA-1, but will likely change within the next year or so.
func ValidRefString ¶
Types ¶
type Blob ¶
type Blob struct {
// contains filtered or unexported fields
}
Blob represents a blob. Use the methods Size, SizedRef and Open to query and get data from Blob.
func NewBlob ¶
func NewBlob(ref Ref, size uint32, newReader func() io.ReadCloser) Blob
NewBlob constructs a Blob from its Ref, size and a function that returns an io.ReadCloser from which the blob can be read. Any error in the function newReader when constructing the io.ReadCloser should be returned upon the first call to Read or Close.
func (Blob) Open ¶
func (b Blob) Open() io.ReadCloser
Open returns an io.ReadCloser that can be used to read the blob data. The caller must close the io.ReadCloser when finished.
type ChanPeeker ¶
type ChanPeeker struct { Ch <-chan SizedRef // contains filtered or unexported fields }
TODO: use Generics if/when available
func (*ChanPeeker) Closed ¶
func (cp *ChanPeeker) Closed() bool
func (*ChanPeeker) ConsumeAll ¶
func (cp *ChanPeeker) ConsumeAll()
func (*ChanPeeker) MustPeek ¶
func (cp *ChanPeeker) MustPeek() SizedRef
func (*ChanPeeker) MustTake ¶
func (cp *ChanPeeker) MustTake() SizedRef
func (*ChanPeeker) Peek ¶
func (cp *ChanPeeker) Peek() (sr SizedRef, ok bool)
func (*ChanPeeker) Take ¶
func (cp *ChanPeeker) Take() (sr SizedRef, ok bool)
type DirFetcher ¶
type DirFetcher struct {
// contains filtered or unexported fields
}
func NewConfigDirFetcher ¶
func NewConfigDirFetcher() *DirFetcher
func NewSimpleDirectoryFetcher ¶
func NewSimpleDirectoryFetcher(dir string) *DirFetcher
func (*DirFetcher) Fetch ¶
func (df *DirFetcher) Fetch(r Ref) (file types.ReadSeekCloser, size int64, err error)
func (*DirFetcher) FetchStreaming ¶
func (df *DirFetcher) FetchStreaming(r Ref) (file io.ReadCloser, size int64, err error)
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore stores blobs in memory and is a Fetcher and StreamingFetcher. Its zero value is usable.
func (*MemoryStore) FetchStreaming ¶
func (s *MemoryStore) FetchStreaming(b Ref) (file io.ReadCloser, size int64, err error)
type Ref ¶
type Ref struct {
// contains filtered or unexported fields
}
Ref is a reference to a Camlistore blob. It is used as a value type and supports equality (with ==) and the ability to use it as a map key.
func ParseBytes ¶
ParseBytes is like Parse, but parses from a byte slice.
func ParseOrZero ¶
Parse parse s as a blobref. If s is invalid, a zero Ref is returned which can be tested with the Valid method.
func RefFromHash ¶
RefFromHash returns a blobref representing the given hash. It panics if the hash isn't of a known type.
func RefFromString ¶
RefFromString returns a blobref from the given string, for the currently recommended hash function
func SHA1FromBytes ¶
SHA1FromBytes returns a SHA-1 blobref of the provided bytes.
func SHA1FromString ¶
SHA1FromString returns a SHA-1 blobref of the provided string.
func (Ref) Digest ¶
Digest returns the lower hex digest of the blobref, without the e.g. "sha1-" prefix. It panics if r is zero.
func (Ref) DigestPrefix ¶
func (Ref) HashName ¶
HashName returns the lowercase hash function name of the reference. It panics if r is zero.
func (Ref) IsSupported ¶
func (Ref) MarshalBinary ¶
MarshalBinary implements Go's encoding.BinaryMarshaler interface.
func (Ref) MarshalJSON ¶
func (*Ref) UnmarshalBinary ¶
UnmarshalBinary implements Go's encoding.BinaryUnmarshaler interface.
func (*Ref) UnmarshalJSON ¶
type SeekFetcher ¶
type SeekFetcher interface { // Fetch returns a blob. If the blob is not found then // os.ErrNotExist should be returned for the error (not a wrapped // error with a ErrNotExist inside) // // The caller should close blob. Fetch(Ref) (blob types.ReadSeekCloser, size int64, err error) }
func NewSerialFetcher ¶
func NewSerialFetcher(fetchers ...SeekFetcher) SeekFetcher
func SeekerFromStreamingFetcher ¶
func SeekerFromStreamingFetcher(f StreamingFetcher) SeekFetcher
SeekerFromStreamingFetcher returns the most efficient implementation of a seeking fetcher from a provided streaming fetcher.
type SeekTester ¶
type SeekTester interface {
IsFetcherASeeker() bool
}
SeekTester is the interface implemented by storage implementations that don't know until runtime whether or not their StreamingFetcher happens to also return a ReadCloser that's also a ReadSeekCloser.
type SizedByRef ¶
type SizedByRef []SizedRef
SizedByRef sorts SizedRefs by their blobref.
func (SizedByRef) Len ¶
func (s SizedByRef) Len() int
func (SizedByRef) Less ¶
func (s SizedByRef) Less(i, j int) bool
func (SizedByRef) Swap ¶
func (s SizedByRef) Swap(i, j int)
type SizedRef ¶
SizedRef is like a Ref but includes a size. It should also be used as a value type and supports equality.
type StreamingFetcher ¶
type StreamingFetcher interface { // FetchStreaming returns a blob. If the blob is not found then // os.ErrNotExist should be returned for the error (not a wrapped // error with a ErrNotExist inside) // // The caller should close blob. FetchStreaming(Ref) (blob io.ReadCloser, size int64, err error) }
StreamingFetcher is the minimal interface for retrieving a blob from storage. The full storage interface is blobserver.Stoage.
func NewSerialStreamingFetcher ¶
func NewSerialStreamingFetcher(fetchers ...StreamingFetcher) StreamingFetcher