From 4ae992cf9829564b68e9a21941e616ae591c8108 Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Fri, 14 Jul 2023 01:15:18 +0200 Subject: [PATCH] Fix a bug in file upload, where the reader doesn't fully read till buffer full --- file.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/file.go b/file.go index 3e5e870..81d4417 100644 --- a/file.go +++ b/file.go @@ -441,11 +441,11 @@ func (protonDrive *ProtonDrive) uploadAndCollectBlockData(ctx context.Context, n shouldContinue := true for i := 1; shouldContinue; i++ { // read at most data of size UPLOAD_BLOCK_SIZE + // for some reason, .Read might not actually read up to buffer size -> use io.ReadFull data := make([]byte, UPLOAD_BLOCK_SIZE) // FIXME: get block size from the server config instead of hardcoding it - readBytes, err := file.Read(data) - + readBytes, err := io.ReadFull(file, data) if err != nil { - if err == io.EOF { + if err == io.EOF || err == io.ErrUnexpectedEOF { // might still have data to read! if readBytes == 0 { break