From 4ee6bc4fcac47edeea1f1e9fd5fbfd3ef595bbca Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 25 May 2014 20:16:11 +0800 Subject: fix for new git api --- routers/repo/download.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'routers/repo/download.go') diff --git a/routers/repo/download.go b/routers/repo/download.go index 5df78dc7..ac9c390b 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) { -- cgit v1.2.3