aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/packfile.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-10-16 10:11:39 +0200
committerGitHub <noreply@github.com>2018-10-16 10:11:39 +0200
commit41d6f2c31e68a9fdcbff4a3da8c40247f1293cc9 (patch)
tree655fed8324e58a6ba44ef45f1bb2e090abe26451 /plumbing/format/packfile/packfile.go
parent8153e040f68da6002096ef177a11510f4fb06769 (diff)
parent6faf286b97ff2e13fbdaf2c6179f8aef36b4498c (diff)
downloadgo-git-41d6f2c31e68a9fdcbff4a3da8c40247f1293cc9.tar.gz
Merge pull request #982 from keybase/strib/gh-KBFS-3474-object-sizes
tree: add a Size() method for getting plaintext size
Diffstat (limited to 'plumbing/format/packfile/packfile.go')
-rw-r--r--plumbing/format/packfile/packfile.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/plumbing/format/packfile/packfile.go b/plumbing/format/packfile/packfile.go
index 852a834..0d13066 100644
--- a/plumbing/format/packfile/packfile.go
+++ b/plumbing/format/packfile/packfile.go
@@ -90,6 +90,24 @@ func (p *Packfile) GetByOffset(o int64) (plumbing.EncodedObject, error) {
return p.nextObject()
}
+// GetSizeByOffset retrieves the size of the encoded object from the
+// packfile with the given offset.
+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