aboutsummaryrefslogtreecommitdiff
path: root/object/store/chain/bytes.go
diff options
context:
space:
mode:
Diffstat (limited to 'object/store/chain/bytes.go')
-rw-r--r--object/store/chain/bytes.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/object/store/chain/bytes.go b/object/store/chain/bytes.go
new file mode 100644
index 00000000..dc9b7906
--- /dev/null
+++ b/object/store/chain/bytes.go
@@ -0,0 +1,46 @@
+package chain
+
+import (
+ "errors"
+ "fmt"
+
+ objectid "codeberg.org/lindenii/furgit/object/id"
+ objectstore "codeberg.org/lindenii/furgit/object/store"
+ objecttype "codeberg.org/lindenii/furgit/object/type"
+)
+
+// ReadBytesFull reads a full serialized object from the first backend that has it.
+func (chain *Chain) ReadBytesFull(id objectid.ObjectID) ([]byte, error) {
+ for i, backend := range chain.backends {
+ full, err := backend.ReadBytesFull(id)
+ if err == nil {
+ return full, nil
+ }
+
+ if errors.Is(err, objectstore.ErrObjectNotFound) {
+ continue
+ }
+
+ return nil, fmt.Errorf("objectstore: backend %d read bytes full: %w", i, err)
+ }
+
+ return nil, objectstore.ErrObjectNotFound
+}
+
+// ReadBytesContent reads an object's type and content bytes from the first backend that has it.
+func (chain *Chain) ReadBytesContent(id objectid.ObjectID) (objecttype.Type, []byte, error) {
+ for i, backend := range chain.backends {
+ ty, content, err := backend.ReadBytesContent(id)
+ if err == nil {
+ return ty, content, nil
+ }
+
+ if errors.Is(err, objectstore.ErrObjectNotFound) {
+ continue
+ }
+
+ return objecttype.TypeInvalid, nil, fmt.Errorf("objectstore: backend %d read bytes content: %w", i, err)
+ }
+
+ return objecttype.TypeInvalid, nil, objectstore.ErrObjectNotFound
+}