diff options
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..b1b4f7c2 --- /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 (fetcher *Fetcher) exactReader(id oid.ObjectID, wantType typ.Type) (io.ReadCloser, int, error) { + gotType, size, rc, err := fetcher.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 +} |
