diff options
author | slene <vslene@gmail.com> | 2014-05-25 20:16:11 +0800 |
---|---|---|
committer | slene <vslene@gmail.com> | 2014-05-28 14:01:41 +0800 |
commit | 4ee6bc4fcac47edeea1f1e9fd5fbfd3ef595bbca (patch) | |
tree | 8867be03be123ea8c84bc92d7d388f6ac85de058 /routers/repo/download.go | |
parent | ab13a29cb530457328cf9d3a2511c2db1d5ccaca (diff) | |
download | gitea-4ee6bc4fcac47edeea1f1e9fd5fbfd3ef595bbca.tar.gz gitea-4ee6bc4fcac47edeea1f1e9fd5fbfd3ef595bbca.zip |
fix for new git api
Diffstat (limited to 'routers/repo/download.go')
-rw-r--r-- | routers/repo/download.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go index 5df78dc7d8..ac9c390b1f 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -5,6 +5,7 @@ package repo import ( + "io" "os" "path/filepath" @@ -26,20 +27,31 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { return } - data, err := blob.Data() + dataRc, err := blob.Data() if err != nil { ctx.Handle(500, "repo.SingleDownload(Data)", err) return } - contentType, isTextFile := base.IsTextFile(data) - _, isImageFile := base.IsImageFile(data) + buf := make([]byte, 1024) + n, _ := dataRc.Read(buf) + if n > 0 { + buf = buf[:n] + } + + defer func() { + dataRc.Close() + }() + + contentType, isTextFile := base.IsTextFile(buf) + _, isImageFile := base.IsImageFile(buf) ctx.Res.Header().Set("Content-Type", contentType) if !isTextFile && !isImageFile { ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename)) ctx.Res.Header().Set("Content-Transfer-Encoding", "binary") } - ctx.Res.Write(data) + ctx.Res.Write(buf) + io.Copy(ctx.Res, dataRc) } func ZipDownload(ctx *middleware.Context, params martini.Params) { |