From 14f33d86a6f64f58abdf9cd109165ba09d80d733 Mon Sep 17 00:00:00 2001 From: ftpgxm Date: Tue, 18 May 2021 14:00:30 +0800 Subject: [PATCH] ... --- client/client.go | 14 +++++++------- readme.md | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index cf4a615..ee51364 100644 --- a/client/client.go +++ b/client/client.go @@ -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 diff --git a/readme.md b/readme.md index 6c2085c..956712d 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,10 @@ -protoc -I=proto --go_out=plugins=grpc:. ./proto/*.proto + +## 下载地址 +``` +https://github.com/google/protobuf +``` + +## 生成 +``` +protoc -I=proto --go_out=plugins=grpc:./dist/ ./proto/*.proto +```