Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakura-Byte committed Jan 31, 2025
1 parent eabeb89 commit b3f2684
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 14 additions & 2 deletions backend/115/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ func (f *Fs) newChunkWriter(
size := src.Size()

chunkSize := f.opt.ChunkSize
if size != -1 {
// size can be -1 here meaning we don't know the size of the incoming file. We use ChunkSize
// buffers here (default 5 MiB). With a maximum number of parts (10,000) this will be a file of
// 48 GiB which seems like a not too unreasonable limit.
if size == -1 {
warnStreamUpload.Do(func() {
fs.Logf(f, "Streaming uploads using chunk size %v will have maximum file size of %v",
f.opt.ChunkSize, fs.SizeSuffix(int64(chunkSize)*int64(uploadParts)))
})
} else {
chunkSize = chunksize.Calculator(src, size, uploadParts, chunkSize)
}

Expand All @@ -199,7 +207,11 @@ func (f *Fs) newChunkWriter(
if err != nil {
return nil, fmt.Errorf("failed to create temp file: %w", err)
}
defer os.Remove(tempFile.Name())
defer func() {
if err := os.Remove(tempFile.Name()); err != nil {
fs.Errorf(w.o, "failed to remove temp file: %v", err)
}
}()
if _, err = io.Copy(tempFile, in); err != nil {
return nil, fmt.Errorf("failed to buffer to temp file: %w", err)
}
Expand Down
1 change: 0 additions & 1 deletion backend/115/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func bufferIO(in io.Reader, size, threshold int64) (out io.Reader, cleanup func(

// bufferIOwithSHA1 buffers the input and calculates its SHA-1
func bufferIOwithSHA1(in io.Reader, size, threshold int64) (sha1sum string, out io.Reader, cleanup func(), err error) {
cleanup = func() {} // 默认空清理函数
hashVal := sha1.New()
tee := io.TeeReader(in, hashVal)

Expand Down

0 comments on commit b3f2684

Please sign in to comment.