File tree 2 files changed +12
-4
lines changed
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,16 @@ type Blob struct {
22
22
// Data gets content of blob all at once and wrap it as io.Reader.
23
23
// This can be very slow and memory consuming for huge content.
24
24
func (b * Blob ) Data () (io.Reader , error ) {
25
- stdout , err := NewCommand ("show" , b .ID .String ()).RunInDirBytes (b .repo .Path )
26
- if err != nil {
27
- return nil , err
25
+ stdout := new (bytes.Buffer )
26
+ stderr := new (bytes.Buffer )
27
+
28
+ // Preallocate memory to save ~50% memory usage on big files.
29
+ stdout .Grow (int (b .Size () + 2048 ))
30
+
31
+ if err := b .DataPipeline (stdout , stderr ); err != nil {
32
+ return nil , concatenateError (err , stderr .String ())
28
33
}
29
- return bytes . NewBuffer ( stdout ) , nil
34
+ return stdout , nil
30
35
}
31
36
32
37
// DataPipeline gets content of blob and write the result or error to stdout or stderr
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ var testBlob = &Blob{
17
17
repo : & Repository {},
18
18
TreeEntry : & TreeEntry {
19
19
ID : MustIDFromString ("176d8dfe018c850d01851b05fb8a430096247353" ),
20
+ ptree : & Tree {
21
+ repo : & Repository {},
22
+ },
20
23
},
21
24
}
22
25
You can’t perform that action at this time.
0 commit comments