You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
768 B

  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "bytes"
  7. "io"
  8. )
  9. // Blob represents a Git object.
  10. type Blob struct {
  11. repo *Repository
  12. *TreeEntry
  13. }
  14. // Data gets content of blob all at once and wrap it as io.Reader.
  15. // This can be very slow and memory consuming for huge content.
  16. func (b *Blob) Data() (io.Reader, error) {
  17. stdout, err := NewCommand("show", b.ID.String()).RunInDirBytes(b.repo.Path)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return bytes.NewBuffer(stdout), nil
  22. }
  23. func (b *Blob) DataPipeline(stdout, stderr io.Writer) error {
  24. return NewCommand("show", b.ID.String()).RunInDirPipeline(b.repo.Path, stdout, stderr)
  25. }