mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Leave initial request open until the viewer is ready to switch to range requests.
This commit is contained in:
parent
945e370d4f
commit
0385131a9a
5 changed files with 57 additions and 24 deletions
|
@ -30,6 +30,7 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
|||
this.numChunksLoaded = 0;
|
||||
this.numChunks = Math.ceil(length / chunkSize);
|
||||
this.manager = manager;
|
||||
this.initialDataLength = 0;
|
||||
}
|
||||
|
||||
// required methods for a stream. if a particular stream does not
|
||||
|
@ -77,11 +78,26 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
|||
}
|
||||
},
|
||||
|
||||
onReceiveInitialData: function (data) {
|
||||
this.bytes.set(data);
|
||||
this.initialDataLength = data.length;
|
||||
var endChunk = this.end === data.length ?
|
||||
this.numChunks : Math.floor(data.length / this.chunkSize);
|
||||
for (var i = 0; i < endChunk; i++) {
|
||||
this.loadedChunks[i] = true;
|
||||
++this.numChunksLoaded;
|
||||
}
|
||||
},
|
||||
|
||||
ensureRange: function ChunkedStream_ensureRange(begin, end) {
|
||||
if (begin >= end) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (end <= this.initialDataLength) {
|
||||
return;
|
||||
}
|
||||
|
||||
var chunkSize = this.chunkSize;
|
||||
var beginChunk = Math.floor(begin / chunkSize);
|
||||
var endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
||||
|
@ -243,10 +259,25 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||
this.callbacksByRequest = {};
|
||||
|
||||
this.loadedStream = new Promise();
|
||||
if (args.initialData) {
|
||||
this.setInitialData(args.initialData);
|
||||
}
|
||||
}
|
||||
|
||||
ChunkedStreamManager.prototype = {
|
||||
|
||||
setInitialData: function ChunkedStreamManager_setInitialData(data) {
|
||||
this.stream.onReceiveInitialData(data);
|
||||
if (this.stream.allChunksLoaded()) {
|
||||
this.loadedStream.resolve(this.stream);
|
||||
} else if (this.msgHandler) {
|
||||
this.msgHandler.send('DocProgress', {
|
||||
loaded: data.length,
|
||||
total: this.length
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
|
||||
return this.loadedStream;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue