aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile
diff options
context:
space:
mode:
authorJeremy Stribling <strib@alum.mit.edu>2018-10-11 16:24:25 -0700
committerJeremy Stribling <strib@alum.mit.edu>2018-10-11 17:12:21 -0700
commit1e1315d5e587d481e73e295dd18e50026af48c79 (patch)
tree5819d378bc667a0f39d51abc230fc678828d5234 /plumbing/format/packfile
parent0bfe038a16551ede1d22bfb54f52c31b646a9e1a (diff)
downloadgo-git-1e1315d5e587d481e73e295dd18e50026af48c79.tar.gz
object: get object size without reading whole object
Signed-off-by: Jeremy Stribling <strib@alum.mit.edu>
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r--plumbing/format/packfile/packfile.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/plumbing/format/packfile/packfile.go b/plumbing/format/packfile/packfile.go
index 852a834..dbd5d4b 100644
--- a/plumbing/format/packfile/packfile.go
+++ b/plumbing/format/packfile/packfile.go
@@ -90,6 +90,22 @@ func (p *Packfile) GetByOffset(o int64) (plumbing.EncodedObject, error) {
return p.nextObject()
}
+func (p *Packfile) GetSizeByOffset(o int64) (size int64, err error) {
+ if _, err := p.s.SeekFromStart(o); err != nil {
+ if err == io.EOF || isInvalid(err) {
+ return 0, plumbing.ErrObjectNotFound
+ }
+
+ return 0, err
+ }
+
+ h, err := p.nextObjectHeader()
+ if err != nil {
+ return 0, err
+ }
+ return h.Length, nil
+}
+
func (p *Packfile) nextObjectHeader() (*ObjectHeader, error) {
h, err := p.s.NextObjectHeader()
p.s.pendingObject = nil