diff options
| author | 2026-03-25 14:34:50 +0000 | |
|---|---|---|
| committer | 2026-03-25 14:34:50 +0000 | |
| commit | e4a7aa0742f5070299d37e8421c99d67f0af3f90 (patch) | |
| tree | 36d89781476a92e61280c5ff232a2773e4092c0e /object/storer/mix/bytes.go | |
| parent | *: delta -> packfile/delta (diff) | |
| signature | No signature | |
*: object/store -> object/storer v0.1.107
Diffstat (limited to 'object/storer/mix/bytes.go')
| -rw-r--r-- | object/storer/mix/bytes.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/object/storer/mix/bytes.go b/object/storer/mix/bytes.go new file mode 100644 index 00000000..d2a7dc0e --- /dev/null +++ b/object/storer/mix/bytes.go @@ -0,0 +1,51 @@ +package mix + +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 one backend that has it. +func (mix *Mix) ReadBytesFull(id objectid.ObjectID) ([]byte, error) { + for i, backend := 0, mix.firstBackend(); backend != nil; i, backend = i+1, mix.nextBackend(backend) { + full, err := backend.ReadBytesFull(id) + if err == nil { + mix.touchBackend(backend) + + 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 one backend +// that has it. +func (mix *Mix) ReadBytesContent(id objectid.ObjectID) (objecttype.Type, []byte, error) { + for i, backend := 0, mix.firstBackend(); backend != nil; i, backend = i+1, mix.nextBackend(backend) { + ty, content, err := backend.ReadBytesContent(id) + if err == nil { + mix.touchBackend(backend) + + 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 +} |
