Merge pull request #10161 from Snuffleupagus/DataLoaded-onProgress
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
This commit is contained in:
commit
d21892933d
@ -1763,12 +1763,9 @@ class WorkerTransport {
|
|||||||
fullReader.headersReady.then(() => {
|
fullReader.headersReady.then(() => {
|
||||||
// If stream or range are disabled, it's our only way to report
|
// If stream or range are disabled, it's our only way to report
|
||||||
// loading progress.
|
// loading progress.
|
||||||
if (!fullReader.isStreamingSupported ||
|
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
||||||
!fullReader.isRangeSupported) {
|
if (this._lastProgress && loadingTask.onProgress) {
|
||||||
if (this._lastProgress) {
|
loadingTask.onProgress(this._lastProgress);
|
||||||
if (loadingTask.onProgress) {
|
|
||||||
loadingTask.onProgress(this._lastProgress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fullReader.onProgress = (evt) => {
|
fullReader.onProgress = (evt) => {
|
||||||
if (loadingTask.onProgress) {
|
if (loadingTask.onProgress) {
|
||||||
@ -1866,6 +1863,14 @@ class WorkerTransport {
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('DataLoaded', function(data) {
|
messageHandler.on('DataLoaded', function(data) {
|
||||||
|
// For consistency: Ensure that progress is always reported when the
|
||||||
|
// entire PDF file has been loaded, regardless of how it was fetched.
|
||||||
|
if (loadingTask.onProgress) {
|
||||||
|
loadingTask.onProgress({
|
||||||
|
loaded: data.length,
|
||||||
|
total: data.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.downloadInfoCapability.resolve(data);
|
this.downloadInfoCapability.resolve(data);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
@ -142,9 +142,20 @@ describe('api', function() {
|
|||||||
// Sanity check to make sure that we fetched the entire PDF file.
|
// Sanity check to make sure that we fetched the entire PDF file.
|
||||||
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
||||||
|
|
||||||
var loadingTask = getDocument(typedArrayPdf);
|
const loadingTask = getDocument(typedArrayPdf);
|
||||||
loadingTask.promise.then(function(data) {
|
|
||||||
expect(data instanceof PDFDocumentProxy).toEqual(true);
|
const progressReportedCapability = createPromiseCapability();
|
||||||
|
loadingTask.onProgress = function(data) {
|
||||||
|
progressReportedCapability.resolve(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
loadingTask.promise,
|
||||||
|
progressReportedCapability.promise,
|
||||||
|
]).then(function(data) {
|
||||||
|
expect(data[0] instanceof PDFDocumentProxy).toEqual(true);
|
||||||
|
expect(data[1].loaded / data[1].total).toEqual(1);
|
||||||
|
|
||||||
loadingTask.destroy().then(done);
|
loadingTask.destroy().then(done);
|
||||||
}).catch(done.fail);
|
}).catch(done.fail);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user