blob.go 521 B

1234567891011121314151617181920212223242526
  1. // Copyright 2014 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. "errors"
  8. "io"
  9. "github.com/Unknwon/com"
  10. )
  11. type Blob struct {
  12. repo *Repository
  13. *TreeEntry
  14. }
  15. func (b *Blob) Data() (io.Reader, error) {
  16. stdout, stderr, err := com.ExecCmdDirBytes(b.repo.Path, "git", "show", b.Id.String())
  17. if err != nil {
  18. return nil, errors.New(string(stderr))
  19. }
  20. return bytes.NewBuffer(stdout), nil
  21. }