FCLauncher/fclauncher/https.go

28 lines
514 B
Go

package main
import (
"fmt"
"io"
"net/http"
)
const BlockSize = 1024
func HttpDownload(path string, out io.Writer) error {
res, err := http.Get("https://gitea.piwalker.net/fclauncher/" + path)
if err != nil {
return err
}
defer res.Body.Close()
var read int64 = 0
for read < res.ContentLength {
count, err := io.CopyN(out, res.Body, BlockSize)
read += count
fmt.Printf("Downloaded %dMB / %dMB\n", read/(1024*1024), res.ContentLength/(1024*1024))
if err != nil {
break
}
}
return nil
}