mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-04 19:11:27 +08:00
【新增】资源管理模块
This commit is contained in:
33
base/file/file.go
Normal file
33
base/file/file.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package utilFile
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
/**
|
||||
* @Description 添加qq群467890197 交流学习
|
||||
* @Author 熊猫
|
||||
* @Date 2022/1/14 11:13
|
||||
**/
|
||||
|
||||
// DownloadFile 会将url下载到本地文件,它会在下载时写入,而不是将整个文件加载到内存中。
|
||||
func DownloadFile(url, filepath string) error {
|
||||
// Get the data
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Create the file
|
||||
out, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
// Write the body to file
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user