aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/download.go
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2021-03-04 19:44:02 -0500
committerMitch Riedstra <mitch@riedstra.us>2021-03-04 19:48:27 -0500
commitb9bb17044a8c2b47c7e96660e27ab645f82bec9d (patch)
tree6c5bff2c5eaaebfc1ce9b01119308dcc39a75253 /cmd/web/download.go
parent3b6f5647b0689abf04be73c3cf00297051753435 (diff)
downloadsteam-export-b9bb17044a8c2b47c7e96660e27ab645f82bec9d.tar.gz
steam-export-b9bb17044a8c2b47c7e96660e27ab645f82bec9d.tar.xz
Further refactoring.
Diffstat (limited to 'cmd/web/download.go')
-rw-r--r--cmd/web/download.go61
1 files changed, 0 insertions, 61 deletions
diff --git a/cmd/web/download.go b/cmd/web/download.go
deleted file mode 100644
index 0238c8c..0000000
--- a/cmd/web/download.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package main
-
-import (
- "fmt"
- "io"
- "net/http"
- "time"
-
- "github.com/gorilla/mux"
-)
-
-func (a *App) HandleDownload(w http.ResponseWriter, r *http.Request) {
- vars := mux.Vars(r)
- game := vars["game"]
-
- a.Library.Lock()
- g, ok := a.Library.Games[game]
- a.Library.Unlock()
- if !ok {
- Logger.Printf("Missing: %s", game)
- http.Error(w, "Game is missing", 404)
- return
- }
-
- w.Header().Add("Content-type", "application/tar")
- w.Header().Add("Estimated-size", fmt.Sprintf("%d", g.Size))
-
- Logger.Printf("Client %s is downloading: %s", r.RemoteAddr, game)
-
- // Invert the writer so we can break up the copy and get progress
- // information in here
- rdr, pwrtr := io.Pipe()
- go func() {
- err := g.Package(pwrtr)
- if err != nil {
- Logger.Println("Error in package writing: ", err)
- }
- }()
-
- var total int64
- start := time.Now()
- for {
- n, err := io.CopyN(w, rdr, 256*1024*1024)
- if err == io.EOF {
- break
- }
- if err != nil {
- Logger.Printf("Client %s Error Sending game: %s", r.RemoteAddr, err)
- // Headers already sent, don't bother sending an error
- return
- }
- total += n
- mb := float64(total / 1024 / 1024)
- rate := mb / time.Since(start).Seconds()
-
- Logger.Printf("Client %s is downloading %s: %0.1f%% done %.2f mb/s",
- r.RemoteAddr, game, float64(total)/float64(g.Size)*100, rate)
- }
-
- Logger.Printf("Client %s finished downloading: %s", r.RemoteAddr, game)
-}