diff options
Diffstat (limited to 'src/storage.cpp')
-rw-r--r-- | src/storage.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/storage.cpp b/src/storage.cpp index 608f82b..6b2e4f8 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -316,6 +316,19 @@ optional<Ref> Storage::ref(const Digest & digest) const return Ref::create(*this, digest); } +Digest PartialStorage::Priv::storeBytes(const vector<uint8_t> & content) const +{ + array<uint8_t, Digest::size> arr; + int ret = blake2b(arr.data(), content.data(), nullptr, + Digest::size, content.size(), 0); + if (ret != 0) + throw runtime_error("failed to compute digest"); + + Digest digest(arr); + backend->storeBytes(digest, content); + return digest; +} + optional<vector<uint8_t>> PartialStorage::Priv::loadBytes(const Digest & digest) const { auto ocontent = backend->loadBytes(digest); @@ -339,6 +352,15 @@ optional<PartialObject> PartialStorage::loadObject(const Digest & digest) const return nullopt; } +PartialRef PartialStorage::storeObject(const PartialObject & obj) const +{ return ref(p->storeBytes(obj.encode())); } + +PartialRef PartialStorage::storeObject(const PartialRecord & val) const +{ return storeObject(PartialObject(val)); } + +PartialRef PartialStorage::storeObject(const Blob & val) const +{ return storeObject(PartialObject(val)); } + optional<Object> Storage::loadObject(const Digest & digest) const { if (auto content = p->loadBytes(digest)) @@ -380,17 +402,7 @@ optional<Digest> Storage::Priv::copy(const ObjectT<S> & pobj, vector<Digest> * m if (fail) return nullopt; - auto content = pobj.encode(); - - array<uint8_t, Digest::size> arr; - int ret = blake2b(arr.data(), content.data(), nullptr, - Digest::size, content.size(), 0); - if (ret != 0) - throw runtime_error("failed to compute digest"); - - Digest digest(arr); - backend->storeBytes(digest, content); - return digest; + return storeBytes(pobj.encode()); } variant<Ref, vector<Digest>> Storage::copy(const PartialRef & pref) const |