whisper-api-server/internal/resources/download.go
xzeldon a025285256
Implement automatic model and Whisper.dll downloading
Additionally, made the following changes:
∙ - Allow listening only on local interfaces
∙ - Update project structure
2023-10-05 21:05:30 +03:00

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
}