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:
Jonas Jenwald 2019-03-27 17:54:05 +01:00
parent f9c58115fc
commit a7273c8efe
4 changed files with 49 additions and 8 deletions

View file

@ -54,19 +54,26 @@ class PDFNodeStream {
this.isFsUrl = this.url.protocol === 'file:';
this.httpHeaders = (this.isHttp && source.httpHeaders) || {};
this._fullRequest = null;
this._fullRequestReader = null;
this._rangeRequestReaders = [];
}
get _progressiveDataLength() {
return (this._fullRequestReader ? this._fullRequestReader._loaded : 0);
}
getFullReader() {
assert(!this._fullRequest);
this._fullRequest = this.isFsUrl ?
assert(!this._fullRequestReader);
this._fullRequestReader = this.isFsUrl ?
new PDFNodeStreamFsFullReader(this) :
new PDFNodeStreamFullReader(this);
return this._fullRequest;
return this._fullRequestReader;
}
getRangeReader(start, end) {
if (end <= this._progressiveDataLength) {
return null;
}
let rangeReader = this.isFsUrl ?
new PDFNodeStreamFsRangeReader(this, start, end) :
new PDFNodeStreamRangeReader(this, start, end);
@ -75,8 +82,8 @@ class PDFNodeStream {
}
cancelAllRequests(reason) {
if (this._fullRequest) {
this._fullRequest.cancel(reason);
if (this._fullRequestReader) {
this._fullRequestReader.cancel(reason);
}
let readers = this._rangeRequestReaders.slice(0);