package kvfiles import ( "encoding/hex" "io/ioutil" "os" "path" "bazil.org/bazil/kv" ) type KVFiles struct { path string } var _ = kv.KV(&KVFiles{}) func (k *KVFiles) Put(key, value []byte) error { tmp, err := ioutil.TempFile(k.path, "put-") if err != nil { return err } defer func() { // silence errcheck _ = os.Remove(tmp.Name()) }() _, err = tmp.Write(value) if err != nil { return err }
"bazil.org/bazil/cas" "bazil.org/bazil/kv" "bazil.org/bazil/tokens" "github.com/codahale/blake2" "golang.org/x/crypto/nacl/secretbox" ) type Convergent struct { // not a CAS because key derives from the plaintext version, but // used like a Fixed Content Storage (FCS) untrusted kv.KV secret *[32]byte } var _ = kv.KV(&Convergent{}) var personalizeKey = []byte(tokens.Blake2bPersonalizationConvergentKey) func (s *Convergent) computeBoxedKey(key []byte) []byte { conf := blake2.Config{ Size: cas.KeySize, Key: s.secret[:], Personal: personalizeKey, } h := blake2.New(&conf) // hash.Hash docs say it never fails _, _ = h.Write(key) return h.Sum(nil) }
package kvmock import "bazil.org/bazil/kv" type InMemory struct { Data map[string]string } var _ = kv.KV(&InMemory{}) func (m *InMemory) Get(key []byte) ([]byte, error) { s, found := m.Data[string(key)] if !found { return nil, kv.NotFound{Key: key} } return []byte(s), nil } func (m *InMemory) Put(key, value []byte) error { if m.Data == nil { m.Data = make(map[string]string) } m.Data[string(key)] = string(value) return nil }
import ( "errors" "bazil.org/bazil/kv" ) type Multi struct { list []kv.KV } func New(k ...kv.KV) *Multi { return &Multi{list: k} } var _ = kv.KV(&Multi{}) func (m *Multi) Get(key []byte) ([]byte, error) { // TODO this needs to be a lot smarter var firstErr error for _, k := range m.list { v, err := k.Get(key) if err == nil { return v, nil } if _, isNotFound := err.(kv.NotFound); !isNotFound && firstErr == nil { firstErr = err } } if firstErr != nil { return nil, firstErr
import ( "io" "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/codes" "bazil.org/bazil/kv" "bazil.org/bazil/peer/wire" ) type KVPeer struct { peer wire.PeerClient } var _ = kv.KV(&KVPeer{}) func (k *KVPeer) Put(key, value []byte) error { ctx := context.TODO() stream, err := k.peer.ObjectPut(ctx) if err != nil { return err } first := true const chunkSize = 4 * 1024 * 1024 var chunk []byte buf := value for len(buf) > 0 { size := chunkSize