From cd96dee9822c8b744526ba862fd8b5ec0e2c30ff Mon Sep 17 00:00:00 2001 From: Richard Mahn Date: Sat, 29 Jun 2019 16:51:10 -0400 Subject: Fixes #7292 - API File Contents bug (#7301) --- modules/git/blob.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'modules/git/blob.go') diff --git a/modules/git/blob.go b/modules/git/blob.go index 73ac89dfdf..68147673a3 100644 --- a/modules/git/blob.go +++ b/modules/git/blob.go @@ -37,6 +37,19 @@ func (b *Blob) Name() string { return b.name } +// GetBlobContent Gets the content of the blob as raw text +func (b *Blob) GetBlobContent() (string, error) { + dataRc, err := b.DataAsync() + if err != nil { + return "", err + } + defer dataRc.Close() + buf := make([]byte, 1024) + n, _ := dataRc.Read(buf) + buf = buf[:n] + return string(buf), nil +} + // GetBlobContentBase64 Reads the content of the blob with a base64 encode and returns the encoded string func (b *Blob) GetBlobContentBase64() (string, error) { dataRc, err := b.DataAsync() -- cgit v1.2.3