io.Copy 无法复制到文件,io.Copy 无法准确复制超过 600MB,没有错误,仅复制 100MB 左右(或 http.Get?)
发布时间:2022-06-20 15:39:39 351
相关标签:
package installer
import (
"bufio"
"fmt"
"io"
"log"
"net/http"
"os"
"time"
"github.com/briandowns/spinner"
)
func Install(url, pathOut string) {
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
fmt.Printf("Installing from '%s'\n", url)
resp, err := http.Get(url)
if err != nil {
log.Fatalln("Failed to get url '"+url+"':", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Fatalln("Response Status Code for installing/getting '"+url+"' is not successful:", resp.StatusCode)
}
// Create file
out, err := os.Create(pathOut)
if err != nil {
log.Fatalln("Failed to create '"+pathOut+"' file:", err)
}
defer out.Close()
// Write body to file
written, err := io.Copy(out, resp.Body)
if err != nil {
log.Fatalln("Failed to write url '"+url+"' response body to '"+pathOut+"' file:", err)
}
fmt.Println(written)
s.Stop()
}
notshown
)
Install("https://github.com/notshown/archive/refs/heads/main.zip", path + string(os.PathSeparator) + "Whatever.zip")
基本上io.Copy
在这里,仅将大约100MB的数据复制到所创建的文件中,而假设复制的数据超过600MB。
io.Copy
甚至没有记录错误. 它完全没有声音,没有错误,也没有完成它的工作。我认为这是一个BUG。
fmt.Println(written)
印刷品-143402096
.
这有什么问题吗?文件是否太大?也许吧,但这不应该出错吗?
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报