aboutsummaryrefslogtreecommitdiff
path: root/storage/memory
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2017-10-02 14:26:26 +0200
committerLaria Carolin Chabowski <laria@laria.me>2017-10-03 15:01:38 +0200
commitdb0c023fd0d756912c3f575c6ac65e99fda573cc (patch)
treef5e507c519f591e401fbb46bb77118d252b37612 /storage/memory
parent7f0771d0a9caf2d3294bfced9e66fac03334d9ba (diff)
downloadpetrific-db0c023fd0d756912c3f575c6ac65e99fda573cc.tar.gz
petrific-db0c023fd0d756912c3f575c6ac65e99fda573cc.tar.bz2
petrific-db0c023fd0d756912c3f575c6ac65e99fda573cc.zip
Add filter storage method
Also remove de/encryption in cloud storage, can be provided with a filter storage
Diffstat (limited to 'storage/memory')
-rw-r--r--storage/memory/memory.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/storage/memory/memory.go b/storage/memory/memory.go
index 456049b..e73c51a 100644
--- a/storage/memory/memory.go
+++ b/storage/memory/memory.go
@@ -22,12 +22,18 @@ func MemoryStorageFromConfig(conf config.Config, name string) (storage.Storage,
return NewMemoryStorage(), nil
}
+func copyBytes(b []byte) []byte {
+ c := make([]byte, len(b))
+ copy(c, b)
+ return c
+}
+
func (ms MemoryStorage) Get(id objects.ObjectId) ([]byte, error) {
b, ok := ms.objects[id.String()]
if !ok {
return nil, storage.ObjectNotFound
}
- return b, nil
+ return copyBytes(b), nil
}
func (ms MemoryStorage) Has(id objects.ObjectId) (bool, error) {
@@ -36,7 +42,7 @@ func (ms MemoryStorage) Has(id objects.ObjectId) (bool, error) {
}
func (ms MemoryStorage) Set(id objects.ObjectId, typ objects.ObjectType, raw []byte) error {
- ms.objects[id.String()] = raw
+ ms.objects[id.String()] = copyBytes(raw)
ms.bytype[typ] = append(ms.bytype[typ], id)
return nil