You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
594 B
27 lines
594 B
package storage
|
|
|
|
type uploadProgress struct {
|
|
lastUploadedBytes int64
|
|
progress func(totalBytes, uploadedBytes int64)
|
|
}
|
|
|
|
func newUploadProgress(progressHandler func(totalBytes, uploadedBytes int64)) *uploadProgress {
|
|
return &uploadProgress{
|
|
lastUploadedBytes: 0,
|
|
progress: progressHandler,
|
|
}
|
|
}
|
|
|
|
func (p *uploadProgress) onProgress(totalBytes, uploadedBytes int64) {
|
|
if p.progress == nil {
|
|
return
|
|
}
|
|
|
|
if p.lastUploadedBytes >= uploadedBytes {
|
|
// 过滤重新上传的场景
|
|
return
|
|
}
|
|
p.lastUploadedBytes = uploadedBytes
|
|
p.progress(totalBytes, uploadedBytes)
|
|
}
|