1package git23import (4 "bytes"5 "context"6 "io"7)89// Blob is a blob object.10type Blob struct {11 *TreeEntry12}1314// Bytes reads and returns the content of the blob all at once in bytes. This can15// be very slow and memory consuming for huge content.16func (b *Blob) Bytes(ctx context.Context) ([]byte, error) {17 stdout := new(bytes.Buffer)1819 // Preallocate memory to save ~50% memory usage on big files.20 if size := b.Size(ctx); size > 0 && size < int64(^uint(0)>>1) {21 stdout.Grow(int(size))22 }2324 if err := b.Pipe(ctx, stdout); err != nil {25 return nil, err26 }27 return stdout.Bytes(), nil28}2930// Pipe reads the content of the blob and pipes stdout to the supplied io.Writer.31func (b *Blob) Pipe(ctx context.Context, stdout io.Writer) error {32 return pipe(ctx, b.parent.repo.path, []string{"show", "--end-of-options", b.id.String()}, nil, stdout)33}