This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,17 @@ func (t *Tree) File(path string) (*File, error) {
8787 return NewFile (path , e .Mode , blob ), nil
8888}
8989
90+ // Size returns the plaintext size of an object, without reading it
91+ // into memory.
92+ func (t * Tree ) Size (path string ) (int64 , error ) {
93+ e , err := t .FindEntry (path )
94+ if err != nil {
95+ return 0 , ErrEntryNotFound
96+ }
97+
98+ return t .s .EncodedObjectSize (e .Hash )
99+ }
100+
90101// Tree returns the tree identified by the `path` argument.
91102// The path is interpreted as relative to the tree receiver.
92103func (t * Tree ) Tree (path string ) (* Tree , error ) {
Original file line number Diff line number Diff line change @@ -98,6 +98,12 @@ func (s *TreeSuite) TestFileFailsWithExistingTrees(c *C) {
9898 c .Assert (err , Equals , ErrFileNotFound )
9999}
100100
101+ func (s * TreeSuite ) TestSize (c * C ) {
102+ size , err := s .Tree .Size ("LICENSE" )
103+ c .Assert (err , IsNil )
104+ c .Assert (size , Equals , int64 (1072 ))
105+ }
106+
101107func (s * TreeSuite ) TestFiles (c * C ) {
102108 var count int
103109 err := s .Tree .Files ().ForEach (func (f * File ) error {
You can’t perform that action at this time.
0 commit comments