@@ -9,6 +9,7 @@ import { AddCancellationHandler } from "../../private/model/AddCancellationHandl
99import { StreamUtils } from "../../private/StreamUtils" ;
1010import { BlobLike , UploadManagerParams , UploadSource } from "../shared/CommonTypes" ;
1111import { UploadManagerFetchUtils } from "../../private/UploadManagerFetchUtils" ;
12+ import { ProgressStream } from "./ProgressStream" ;
1213
1314type UploadManagerNodeInit =
1415 | undefined
@@ -96,27 +97,17 @@ export class UploadManager extends UploadManagerBase<UploadSourceProcessedNode,
9697 part : UploadPart ,
9798 contentLength : number ,
9899 source : UploadSourceProcessedNode ,
99- onProgress : ( bytesSentDelta : number ) => void ,
100+ onProgress : ( totalBytesTransferred : number ) => void ,
100101 addCancellationHandler : AddCancellationHandler
101102 ) : 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 ) ;
115106
116107 return await UploadManagerFetchUtils . doPutUploadPart (
117108 this . config ,
118109 part ,
119- this . coerceRequestBody ( streamWithProgress ) ,
110+ this . coerceRequestBody ( progressStream ) ,
120111 contentLength ,
121112 addCancellationHandler
122113 ) ;
0 commit comments