From e4a7aa0742f5070299d37e8421c99d67f0af3f90 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Wed, 25 Mar 2026 14:34:50 +0000 Subject: *: object/store -> object/storer --- object/storer/chain/bytes.go | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 object/storer/chain/bytes.go (limited to 'object/storer/chain/bytes.go') diff --git a/object/storer/chain/bytes.go b/object/storer/chain/bytes.go new file mode 100644 index 00000000..c3ec1eb8 --- /dev/null +++ b/object/storer/chain/bytes.go @@ -0,0 +1,46 @@ +package chain + +import ( + "errors" + "fmt" + + objectid "codeberg.org/lindenii/furgit/object/id" + "codeberg.org/lindenii/furgit/object/storer" + 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, objectstorer.ErrObjectNotFound) { + continue + } + + return nil, fmt.Errorf("objectstorer: backend %d read bytes full: %w", i, err) + } + + return nil, objectstorer.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, objectstorer.ErrObjectNotFound) { + continue + } + + return objecttype.TypeInvalid, nil, fmt.Errorf("objectstorer: backend %d read bytes content: %w", i, err) + } + + return objecttype.TypeInvalid, nil, objectstorer.ErrObjectNotFound +} -- cgit v1.3.1-10-gc9f91