|
|
@ -13,14 +13,9 @@ import ( |
|
|
|
"github.com/gogits/gogs/modules/middleware" |
|
|
|
"github.com/gogits/gogs/modules/middleware" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func ServeBlob(ctx *middleware.Context, blob *git.Blob) error { |
|
|
|
func ServeData(ctx *middleware.Context, name string, reader io.Reader) error { |
|
|
|
dataRc, err := blob.Data() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf := make([]byte, 1024) |
|
|
|
buf := make([]byte, 1024) |
|
|
|
n, _ := dataRc.Read(buf) |
|
|
|
n, _ := reader.Read(buf) |
|
|
|
if n > 0 { |
|
|
|
if n > 0 { |
|
|
|
buf = buf[:n] |
|
|
|
buf = buf[:n] |
|
|
|
} |
|
|
|
} |
|
|
@ -39,10 +34,19 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Resp.Write(buf) |
|
|
|
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 err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ServeData(ctx, ctx.Repo.TreeName, dataRc) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SingleDownload(ctx *middleware.Context) { |
|
|
|
func SingleDownload(ctx *middleware.Context) { |
|
|
|
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName) |
|
|
|
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|