mirror of
https://github.com/aykhans/movier.git
synced 2025-12-14 01:29:20 +00:00
Rewritten in go and python
This commit is contained in:
31
server/pkg/dto/download.go
Normal file
31
server/pkg/dto/download.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func DownloadAndExtractGz(url, downloadFilepath, extractFilepath string) error {
|
||||
if err := Download(url, downloadFilepath); err != nil {
|
||||
return err
|
||||
}
|
||||
return ExtractGzFile(downloadFilepath, extractFilepath)
|
||||
}
|
||||
|
||||
func Download(url, filepath string) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
out, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user