mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
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.
This commit is contained in:
parent
bfd17b2586
commit
01deb085f8
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
import { arrayBuffersToBytes, MissingDataException } from "./core_utils.js";
|
||||
import { assert } from "../shared/util.js";
|
||||
import { assert, MathClamp } from "../shared/util.js";
|
||||
import { Stream } from "./stream.js";
|
||||
|
||||
class ChunkedStream extends Stream {
|
||||
@ -511,7 +511,11 @@ class ChunkedStreamManager {
|
||||
}
|
||||
|
||||
this.msgHandler.send("DocProgress", {
|
||||
loaded: stream.numChunksLoaded * chunkSize,
|
||||
loaded: MathClamp(
|
||||
stream.numChunksLoaded * chunkSize,
|
||||
stream.progressiveDataLength,
|
||||
length
|
||||
),
|
||||
total: length,
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user