...
This commit is contained in:
parent
82ce7ad073
commit
14f33d86a6
@ -124,7 +124,7 @@ func Download(filePath string, client transportpb.FileServiceClient) (err error)
|
||||
}
|
||||
|
||||
for i := len(downloadContext.tempList) - 1; i >= 0; i-- {
|
||||
err = appendToFile(downloadContext.file.filePath, string(readFile(downloadContext.tempList[i])))
|
||||
err = appendToFile(downloadContext.file.filePath, readFile(downloadContext.tempList[i]))
|
||||
if err != nil {
|
||||
log.Println(err.Error(), "下载失败,请重试")
|
||||
return
|
||||
@ -161,11 +161,11 @@ func startDownloadTask(filePath string, tempFilePath string, b *block, client tr
|
||||
log.Fatalf("下载异常 : %v\n", err)
|
||||
}
|
||||
|
||||
fp, err := os.OpenFile(tempFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0755)
|
||||
err = createFileOnly(tempFilePath)
|
||||
if err != nil {
|
||||
log.Fatalf("文件打开异常: %s\n", err)
|
||||
log.Println(err.Error())
|
||||
panic(err)
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
var recvSize int64 = 0
|
||||
|
||||
@ -180,7 +180,7 @@ func startDownloadTask(filePath string, tempFilePath string, b *block, client tr
|
||||
recvSize += int64(blockSize)
|
||||
|
||||
if blockSize != 0 {
|
||||
_, err = fp.Write(block)
|
||||
err := appendToFile(tempFilePath, block)
|
||||
if err != nil {
|
||||
log.Fatalf("临时文件保存异常: %s\n", err)
|
||||
}
|
||||
@ -410,7 +410,7 @@ func checkBlockStat(filePath string, b *block) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func appendToFile(fileName string, content string) error {
|
||||
func appendToFile(fileName string, content []byte) error {
|
||||
// 以只写的模式,打开文件
|
||||
f, err := os.OpenFile(fileName, os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
@ -419,7 +419,7 @@ func appendToFile(fileName string, content string) error {
|
||||
// 查找文件末尾的偏移量
|
||||
n, _ := f.Seek(0, os.SEEK_END)
|
||||
// 从末尾的偏移量开始写入内容
|
||||
_, err = f.WriteAt([]byte(content), n)
|
||||
_, err = f.WriteAt(content, n)
|
||||
}
|
||||
defer f.Close()
|
||||
return err
|
||||
|
||||
Loading…
Reference in New Issue
Block a user