mirror of
https://github.com/xzeldon/whisper-api-server.git
synced 2024-12-27 10:35:46 +00:00
xzeldon
a025285256
Additionally, made the following changes: ∙ - Allow listening only on local interfaces ∙ - Update project structure
39 lines
542 B
Go
39 lines
542 B
Go
package resources
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/schollz/progressbar/v3"
|
|
)
|
|
|
|
func DownloadFile(url string, filepath string) error {
|
|
out, err := os.Create(filepath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer out.Close()
|
|
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
fileSize := resp.ContentLength
|
|
bar := progressbar.DefaultBytes(
|
|
fileSize,
|
|
"Downloading",
|
|
)
|
|
|
|
writer := io.MultiWriter(out, bar)
|
|
|
|
_, err = io.Copy(writer, resp.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|