Skip to content

Commit 01deb08

Browse files
committed
Improve progress reporting in the ChunkedStreamManager
Currently there's two small bugs, which have existed around a decade, in the `loaded` property that's sent via the "DocProgress" message from the `ChunkedStreamManager.prototype.onReceiveData` method. - When the entire PDF has loaded the `loaded` property can become larger than the `total` property, which obviously doesn't make sense. This happens whenever the size of the PDF is *not* a multiple of the `rangeChunkSize` API-option, which is a very common situation. - When streaming is being used, the `loaded` property can become smaller than the actually loaded amount of data. This happens whenever the size of a streamed chunk is *not* a multiple of the `rangeChunkSize` API-option, which is a common situation.
1 parent bfd17b2 commit 01deb08

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/core/chunked_stream.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import { arrayBuffersToBytes, MissingDataException } from "./core_utils.js";
17-
import { assert } from "../shared/util.js";
17+
import { assert, MathClamp } from "../shared/util.js";
1818
import { Stream } from "./stream.js";
1919

2020
class ChunkedStream extends Stream {
@@ -511,7 +511,11 @@ class ChunkedStreamManager {
511511
}
512512

513513
this.msgHandler.send("DocProgress", {
514-
loaded: stream.numChunksLoaded * chunkSize,
514+
loaded: MathClamp(
515+
stream.numChunksLoaded * chunkSize,
516+
stream.progressiveDataLength,
517+
length
518+
),
515519
total: length,
516520
});
517521
}

0 commit comments

Comments
 (0)