diff options
| author | 2026-06-08 07:15:10 +0000 | |
|---|---|---|
| committer | 2026-06-08 07:15:10 +0000 | |
| commit | 11ecd10958ce91d48c6d0aa64361a63c12d4ef2d (patch) | |
| tree | fa4e00de2bc36ab82d7bf228ddd8cd704940eff1 /object/fetch/reader.go | |
| parent | object/fetch: Port tag (diff) | |
object/fetch: Port reader
Diffstat (limited to 'object/fetch/reader.go')
| -rw-r--r-- | object/fetch/reader.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/object/fetch/reader.go b/object/fetch/reader.go new file mode 100644 index 00000000..197efd84 --- /dev/null +++ b/object/fetch/reader.go @@ -0,0 +1,26 @@ +package fetch + +import ( + "io" + + "lindenii.org/go/furgit/errs" + oid "lindenii.org/go/furgit/object/id" + "lindenii.org/go/furgit/object/typ" +) + +// exactReader reads one object's content stream +// and verifies that its header type matches wantType. +func (r *Fetcher) exactReader(id oid.ObjectID, wantType typ.Type) (io.ReadCloser, int64, error) { + gotType, size, rc, err := r.store.ReadReaderContent(id) + if err != nil { + return nil, 0, wrapObjectReadError(id, err) + } + + if gotType != wantType { + _ = rc.Close() + + return nil, 0, &errs.ObjectTypeError{OID: id, Got: gotType, Want: wantType} + } + + return rc, size, nil +} |
