tiktok-dl/utils/downloadFile.go

25 lines
433 B
Go
Raw Normal View History

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