fix: emit final 100% download progress for empty response body
onDownloadProgress never fired a completion event when the response body was empty (e.g. a 200 with Content-Length: 0), since the final callback in the transform stream's flush() was gated behind a chunk having been read. Report the final progress unconditionally, falling back to an empty chunk when the stream produced none. Closes #878
This commit is contained in:
1 parent
ee0d0d0437
commit
1cf8f269f3
2 files changed
+23
-1
No files matched your search
@@ -70,8 +70,10 @@ const withProgress = (stream: ReadableStream<Uint8Array>, totalBytes: number, on
|
||||
flush() {
|
||||
if (previousChunk) {
|
||||
transferredBytes += previousChunk.byteLength;
|
||||
onProgress?.({percent: 1, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes}, previousChunk);
|
||||
}
|
||||
|
||||
// Always report completion, even for an empty stream, so consumers can rely on a final 100% event.
|
||||
onProgress?.({percent: 1, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes}, previousChunk ?? new Uint8Array());
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user