diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-10-16 10:11:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-16 10:11:39 +0200 |
commit | 41d6f2c31e68a9fdcbff4a3da8c40247f1293cc9 (patch) | |
tree | 655fed8324e58a6ba44ef45f1bb2e090abe26451 /plumbing/object/tree.go | |
parent | 8153e040f68da6002096ef177a11510f4fb06769 (diff) | |
parent | 6faf286b97ff2e13fbdaf2c6179f8aef36b4498c (diff) | |
download | go-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/object/tree.go')
-rw-r--r-- | plumbing/object/tree.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go index c36a137..78d61a1 100644 --- a/plumbing/object/tree.go +++ b/plumbing/object/tree.go @@ -87,6 +87,17 @@ func (t *Tree) File(path string) (*File, error) { return NewFile(path, e.Mode, blob), nil } +// Size returns the plaintext size of an object, without reading it +// into memory. +func (t *Tree) Size(path string) (int64, error) { + e, err := t.FindEntry(path) + if err != nil { + return 0, ErrEntryNotFound + } + + return t.s.EncodedObjectSize(e.Hash) +} + // Tree returns the tree identified by the `path` argument. // The path is interpreted as relative to the tree receiver. func (t *Tree) Tree(path string) (*Tree, error) { |