mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Avoid dispatching range requests to fetch PDF data that's already loaded with streaming (PR 10675 follow-up)
*Please note:* This patch purposely ignores `src/display/network.js`, since its support for progressive reading depends on the non-standard `moz-chunked-arraybuffer` responseType which is currently in the process of being removed.
This commit is contained in:
parent
f9c58115fc
commit
a7273c8efe
4 changed files with 49 additions and 8 deletions
|
@ -1814,6 +1814,21 @@ class WorkerTransport {
|
|||
const rangeReader =
|
||||
this._networkStream.getRangeReader(data.begin, data.end);
|
||||
|
||||
// When streaming is enabled, it's possible that the data requested here
|
||||
// has already been fetched via the `_fullRequestReader` implementation.
|
||||
// However, given that the PDF data is loaded asynchronously on the
|
||||
// main-thread and then sent via `postMessage` to the worker-thread,
|
||||
// it may not have been available during parsing (hence the attempt to
|
||||
// use range requests here).
|
||||
//
|
||||
// To avoid wasting time and resources here, we'll thus *not* dispatch
|
||||
// range requests if the data was already loaded but has not been sent to
|
||||
// the worker-thread yet (which will happen via the `_fullRequestReader`).
|
||||
if (!rangeReader) {
|
||||
sink.close();
|
||||
return;
|
||||
}
|
||||
|
||||
sink.onPull = () => {
|
||||
rangeReader.read().then(function({ value, done, }) {
|
||||
if (done) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue