download.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. // "io"
  7. // "os"
  8. // "path/filepath"
  9. // "github.com/Unknwon/com"
  10. // "github.com/gogits/git"
  11. // "github.com/gogits/gogs/modules/base"
  12. "github.com/gogits/gogs/modules/middleware"
  13. )
  14. func SingleDownload(ctx *middleware.Context) {
  15. // treename := params["_1"]
  16. // blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
  17. // if err != nil {
  18. // ctx.Handle(500, "repo.SingleDownload(GetBlobByPath)", err)
  19. // return
  20. // }
  21. // dataRc, err := blob.Data()
  22. // if err != nil {
  23. // ctx.Handle(500, "repo.SingleDownload(Data)", err)
  24. // return
  25. // }
  26. // buf := make([]byte, 1024)
  27. // n, _ := dataRc.Read(buf)
  28. // if n > 0 {
  29. // buf = buf[:n]
  30. // }
  31. // defer func() {
  32. // dataRc.Close()
  33. // }()
  34. // contentType, isTextFile := base.IsTextFile(buf)
  35. // _, isImageFile := base.IsImageFile(buf)
  36. // ctx.Res.Header().Set("Content-Type", contentType)
  37. // if !isTextFile && !isImageFile {
  38. // ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename))
  39. // ctx.Res.Header().Set("Content-Transfer-Encoding", "binary")
  40. // }
  41. // ctx.Res.Write(buf)
  42. // io.Copy(ctx.Res, dataRc)
  43. }