From 2e22099f4bf1a78c4a481d98cb47a7e1975ea65f Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 7 Jun 2026 19:21:17 +0000 Subject: object/store/mix: Add --- object/store/mix/bytes.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 object/store/mix/bytes.go (limited to 'object/store/mix/bytes.go') 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 +} -- cgit v1.3.1-10-gc9f91