diff options
| author | 2026-06-07 19:21:17 +0000 | |
|---|---|---|
| committer | 2026-06-07 19:21:26 +0000 | |
| commit | 2e22099f4bf1a78c4a481d98cb47a7e1975ea65f (patch) | |
| tree | a6081c8c0b4ad676a8a6a26ba98af1632e8c7316 /object/store/mix/bytes.go | |
| parent | internal/mru: Add (diff) | |
object/store/mix: Add
Diffstat (limited to 'object/store/mix/bytes.go')
| -rw-r--r-- | object/store/mix/bytes.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/object/store/mix/bytes.go b/object/store/mix/bytes.go new file mode 100644 index 00000000..2b4d3819 --- /dev/null +++ b/object/store/mix/bytes.go @@ -0,0 +1,52 @@ +package mix + +import ( + "errors" + "fmt" + + "lindenii.org/go/furgit/object/id" + "lindenii.org/go/furgit/object/store" + "lindenii.org/go/furgit/object/typ" +) + +// ReadBytesFull reads a full serialized object +// from the most-recently-used backend that has it. +func (mix *Mix) ReadBytesFull(id id.ObjectID) ([]byte, error) { + for _, backend := range mix.order.Keys() { + full, err := backend.ReadBytesFull(id) + if err == nil { + mix.order.Touch(backend) + + return full, nil + } + + if errors.Is(err, store.ErrObjectNotFound) { + continue + } + + return nil, fmt.Errorf("object/store/mix: read bytes full: %w", err) + } + + return nil, store.ErrObjectNotFound +} + +// ReadBytesContent reads an object's type and content bytes +// from the most-recently-used backend that has it. +func (mix *Mix) ReadBytesContent(id id.ObjectID) (typ.Type, []byte, error) { + for _, backend := range mix.order.Keys() { + ty, content, err := backend.ReadBytesContent(id) + if err == nil { + mix.order.Touch(backend) + + return ty, content, nil + } + + if errors.Is(err, store.ErrObjectNotFound) { + continue + } + + return typ.TypeUnknown, nil, fmt.Errorf("object/store/mix: read bytes content: %w", err) + } + + return typ.TypeUnknown, nil, store.ErrObjectNotFound +} |
