Documentation ¶
Overview ¶
Package cas provides a framework for working with content addressible storage (CAS). This package only provides the interface, as several types of drivers are possible.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VerifyID ¶
VerifyID loads an object from the storage, and checks that the contents have not been corrupted.
func VerifyStorage ¶
VerifyStorage scans the objects in the storage, and checks that the contents have not been corrupted. If there is concurrent access to the storage, some objects may not be checked.
A callback will be called for every mismatch detected. The ID will indicate the item for which the contents don't match. The callback should return true to indicate that the search should continue.
The storage must also support the IndexStorage interface.
Types ¶
type Error ¶
type Error string
Error records errors that are common across all concrete implementations of Storage.
type ID ¶
An ID identifies a piece of content, which can be any binary blob. The ID is a checksum of the content, ensuring that identical data is always mapped to the same ID.
func CreateFromBytes ¶
CreateFromBytes is a utility function that inserts binary data into a storage.
func CreateFromString ¶
CreateFromString is a utility function that inserts binary data into a storage.
type IndexStorage ¶
type IndexStorage interface { // Index will concurrently return all of the IDs currently in the storage. // The completeness or accuracy of the list is undefined when mixed with // concurrent access to the storage. Index(ctx context.Context) (<-chan ID, error) }
IndexStorage is an extension interface for a content-addressable storage (CAS) that can list its contents.
type RemoveStorage ¶
type RemoveStorage interface { Storage // Remove deletes the content associated with the id. Remove(id ID) error }
RemoveStorage is an extension interface for a content-addressable storage (CAS) that can remove items.
type Storage ¶
type Storage interface { // Close releases any resources linked to the storage. Further calls to // any methods are an error. Close() error // Create copies data from the reader into the storage, and returns an ID // that can be used to identify the data. Create(src io.Reader) (ID, error) // Open locates the content associated with the ID, and returns a reader // that can be used to access the data. If the object does not exist in // storage, then the error will be ErrNotExist. Open(id ID) (io.ReadCloser, error) }
Storage represents an open content-addressable storage (CAS). Adding items to the storage should be idempotent. For example, inserting the same content twice should return the same id.
The methods Create and Open should support concurrent access.
Example ¶
package main import ( "fmt" "io/ioutil" "gitlab.com/stone.code/cas" "gitlab.com/stone.code/cas/memory" ) func main() { // Initialize an in-memory store. storage := memory.New() defer storage.Close() // Insert the data into the storage. id, err := cas.CreateFromString(storage, "Hello, world!") if err != nil { fmt.Println("error: ", err) return } // Find the storage based on the ID. r, err := storage.Open(id) if err != nil { fmt.Println("error: ", err) return } defer r.Close() data, err := ioutil.ReadAll(r) if err != nil { fmt.Println("error: ", err) return } fmt.Println(string(data)) }
Output: Hello, world!
Directories ¶
Path | Synopsis |
---|---|
Package castest provides common test cases for testing the behaviour of storage drivers.
|
Package castest provides common test cases for testing the behaviour of storage drivers. |
Package filesystem provides a driver for content addressable storage (CAS) that uses the file system for backing.
|
Package filesystem provides a driver for content addressable storage (CAS) that uses the file system for backing. |
Package memory provides a driver for content addressible storage (CAS) that uses memory for backing.
|
Package memory provides a driver for content addressible storage (CAS) that uses memory for backing. |