mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Ensure that onProgress
is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired. From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded). This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense. However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls. The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread. --- [1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
This commit is contained in:
parent
ecbdc508f7
commit
327f2eb588
2 changed files with 25 additions and 9 deletions
|
@ -142,9 +142,20 @@ describe('api', function() {
|
|||
// Sanity check to make sure that we fetched the entire PDF file.
|
||||
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
||||
|
||||
var loadingTask = getDocument(typedArrayPdf);
|
||||
loadingTask.promise.then(function(data) {
|
||||
expect(data instanceof PDFDocumentProxy).toEqual(true);
|
||||
const loadingTask = getDocument(typedArrayPdf);
|
||||
|
||||
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);
|
||||
}).catch(done.fail);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue