diff options
author | Unknwon <u@gogs.io> | 2015-08-12 04:49:51 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-12 04:49:51 +0800 |
commit | e67659bf8e76763bdfdfe02d87359255b7acd19b (patch) | |
tree | 63f7c467fed06252d263f6d3bfce00bfbe9ceaec /routers/repo/download.go | |
parent | cafde1287ebb58ad6b862e3cc4ef7d4dece82ddb (diff) | |
download | gitea-e67659bf8e76763bdfdfe02d87359255b7acd19b.tar.gz gitea-e67659bf8e76763bdfdfe02d87359255b7acd19b.zip |
fix serve attachment content type
Diffstat (limited to 'routers/repo/download.go')
-rw-r--r-- | routers/repo/download.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go index c71f8d293e..a0a7823b52 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -13,14 +13,9 @@ import ( "github.com/gogits/gogs/modules/middleware" ) -func ServeBlob(ctx *middleware.Context, blob *git.Blob) error { - dataRc, err := blob.Data() - if err != nil { - return err - } - +func ServeData(ctx *middleware.Context, name string, reader io.Reader) error { buf := make([]byte, 1024) - n, _ := dataRc.Read(buf) + n, _ := reader.Read(buf) if n > 0 { buf = buf[:n] } @@ -39,10 +34,19 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error { } } ctx.Resp.Write(buf) - _, err = io.Copy(ctx.Resp, dataRc) + _, err := io.Copy(ctx.Resp, reader) return err } +func ServeBlob(ctx *middleware.Context, blob *git.Blob) error { + dataRc, err := blob.Data() + if err != nil { + return err + } + + return ServeData(ctx, ctx.Repo.TreeName, dataRc) +} + func SingleDownload(ctx *middleware.Context) { blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName) if err != nil { |