Let the PdfManager.requestLoadedStream method return the stream

*This is very old code, and it could thus do with some simplification.*

Note how in the `src/core/worker.js` file we're combining both the `PdfManager.requestLoadedStream` and `PdfManager.onLoadedStream` methods in order to access the stream-data. This seems unnecessary, and it's simple enough to always let the `PdfManager.requestLoadedStream` method return the stream-data as well.
This commit is contained in:
Jonas Jenwald 2022-10-24 16:59:25 +02:00
parent 987062c302
commit bcffbf74f3
2 changed files with 11 additions and 13 deletions

View File

@ -156,7 +156,9 @@ class LocalPdfManager extends BasePdfManager {
return Promise.resolve(); return Promise.resolve();
} }
requestLoadedStream() {} requestLoadedStream() {
return this._loadedStreamPromise;
}
onLoadedStream() { onLoadedStream() {
return this._loadedStreamPromise; return this._loadedStreamPromise;
@ -213,7 +215,7 @@ class NetworkPdfManager extends BasePdfManager {
} }
requestLoadedStream() { requestLoadedStream() {
this.streamManager.requestAllChunks(); return this.streamManager.requestAllChunks();
} }
sendProgressiveData(chunk) { sendProgressiveData(chunk) {

View File

@ -398,8 +398,7 @@ class WorkerMessageHandler {
onFailure(reason); onFailure(reason);
return; return;
} }
pdfManager.requestLoadedStream(); pdfManager.requestLoadedStream().then(function () {
pdfManager.onLoadedStream().then(function () {
ensureNotTerminated(); ensureNotTerminated();
loadDocument(true).then(onSuccess, onFailure); loadDocument(true).then(onSuccess, onFailure);
@ -521,8 +520,7 @@ class WorkerMessageHandler {
}); });
handler.on("GetData", function wphSetupGetData(data) { handler.on("GetData", function wphSetupGetData(data) {
pdfManager.requestLoadedStream(); return pdfManager.requestLoadedStream().then(function (stream) {
return pdfManager.onLoadedStream().then(function (stream) {
return stream.bytes; return stream.bytes;
}); });
}); });
@ -559,20 +557,18 @@ class WorkerMessageHandler {
handler.on( handler.on(
"SaveDocument", "SaveDocument",
function ({ isPureXfa, numPages, annotationStorage, filename }) { function ({ isPureXfa, numPages, annotationStorage, filename }) {
pdfManager.requestLoadedStream();
const newAnnotationsByPage = !isPureXfa
? getNewAnnotationsMap(annotationStorage)
: null;
const promises = [ const promises = [
pdfManager.onLoadedStream(), pdfManager.requestLoadedStream(),
pdfManager.ensureCatalog("acroForm"), pdfManager.ensureCatalog("acroForm"),
pdfManager.ensureCatalog("acroFormRef"), pdfManager.ensureCatalog("acroFormRef"),
pdfManager.ensureDoc("xref"), pdfManager.ensureDoc("xref"),
pdfManager.ensureDoc("startXRef"), pdfManager.ensureDoc("startXRef"),
]; ];
const newAnnotationsByPage = !isPureXfa
? getNewAnnotationsMap(annotationStorage)
: null;
if (newAnnotationsByPage) { if (newAnnotationsByPage) {
for (const [pageIndex, annotations] of newAnnotationsByPage) { for (const [pageIndex, annotations] of newAnnotationsByPage) {
promises.push( promises.push(