diff options
| author | 2026-03-04 14:36:33 +0800 | |
|---|---|---|
| committer | 2026-03-04 14:37:15 +0800 | |
| commit | 4e3357b476690e02945316519c7804e7f07ccb1b (patch) | |
| tree | 009b977bd973761c8b80f448a8242748acf863e1 /objectstore/chain/bytes.go | |
| parent | *: Add package-level docs (diff) | |
| signature | No signature | |
objectstore/chain: Add an actual chain object store v0.1.45
Diffstat (limited to 'objectstore/chain/bytes.go')
| -rw-r--r-- | objectstore/chain/bytes.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/objectstore/chain/bytes.go b/objectstore/chain/bytes.go new file mode 100644 index 00000000..007c7522 --- /dev/null +++ b/objectstore/chain/bytes.go @@ -0,0 +1,54 @@ +package chain + +import ( + "errors" + "fmt" + + "codeberg.org/lindenii/furgit/objectid" + "codeberg.org/lindenii/furgit/objectstore" + "codeberg.org/lindenii/furgit/objecttype" +) + +// 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 { + if backend == nil { + continue + } + + 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 { + if backend == nil { + continue + } + + 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 +} |
