@@ -9,6 +9,7 @@ import { AddCancellationHandler } from "../../private/model/AddCancellationHandl
9
9
import { StreamUtils } from "../../private/StreamUtils" ;
10
10
import { BlobLike , UploadManagerParams , UploadSource } from "../shared/CommonTypes" ;
11
11
import { UploadManagerFetchUtils } from "../../private/UploadManagerFetchUtils" ;
12
+ import { ProgressStream } from "./ProgressStream" ;
12
13
13
14
type UploadManagerNodeInit =
14
15
| undefined
@@ -96,27 +97,17 @@ export class UploadManager extends UploadManagerBase<UploadSourceProcessedNode,
96
97
part : UploadPart ,
97
98
contentLength : number ,
98
99
source : UploadSourceProcessedNode ,
99
- onProgress : ( bytesSentDelta : number ) => void ,
100
+ onProgress : ( totalBytesTransferred : number ) => void ,
100
101
addCancellationHandler : AddCancellationHandler
101
102
) : Promise < { etag : string | undefined ; status : number } > {
102
- // Report progress:
103
- let hasWarned = false ;
104
- let bytesSent = 0 ;
105
- const stream = await this . sliceDataForRequest ( source , part ) ;
106
- const streamWithProgress = stream . on ( "data" , ( data : Partial < Buffer > ) => {
107
- if ( data . byteLength !== undefined ) {
108
- bytesSent += data . byteLength ;
109
- onProgress ( bytesSent ) ;
110
- } else if ( ! hasWarned ) {
111
- hasWarned = true ;
112
- console . warn ( "Expected stream to contain buffers, but it did not, so upload progress won't be reported." ) ;
113
- }
114
- } ) ;
103
+ const inputStream = await this . sliceDataForRequest ( source , part ) ;
104
+ const progressStream = new ProgressStream ( { onProgress } ) ;
105
+ inputStream . pipe ( progressStream ) ;
115
106
116
107
return await UploadManagerFetchUtils . doPutUploadPart (
117
108
this . config ,
118
109
part ,
119
- this . coerceRequestBody ( streamWithProgress ) ,
110
+ this . coerceRequestBody ( progressStream ) ,
120
111
contentLength ,
121
112
addCancellationHandler
122
113
) ;
0 commit comments