aboutsummaryrefslogtreecommitdiff
path: root/object/fetch/reader.go
blob: 197efd8469c364e5415102572a47cc8aef130a60 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
}