tiktok-dl/utils/downloadFile.go

27 lines
516 B
Go
Raw Normal View History

2020-01-19 04:11:53 +02:00
package utils
import (
"io"
"net/http"
"os"
2020-03-22 02:10:24 +02:00
2020-04-12 03:22:00 +03:00
checkErr "github.com/pikami/tiktok-dl/utils/checkErr"
2020-01-19 04:11:53 +02:00
)
// DownloadFile - Downloads content from `url` and stores it in `outputPath`
func DownloadFile(outputPath string, url string) {
// Get the data
resp, err := http.Get(url)
2020-03-22 02:10:24 +02:00
checkErr.CheckErr(err)
2020-01-19 04:11:53 +02:00
defer resp.Body.Close()
// Create the file
out, err := os.Create(outputPath)
2020-03-22 02:10:24 +02:00
checkErr.CheckErr(err)
2020-01-19 04:11:53 +02:00
defer out.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
2020-03-22 02:10:24 +02:00
checkErr.CheckErr(err)
2020-01-19 04:11:53 +02:00
}