mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Improve the handling getBaseStreams
, on the various Stream implementations
The way that `getBaseStreams` is currently handled has bothered me from time to time, especially how we're checking if the method exists before calling it. By adding a dummy `BaseStream.getBaseStreams` method, and having the call-sites simply check the return value, we can improve some of the relevant code. Note in particular how the `ObjectLoader._walk` method didn't actually check that the data in question is a Stream instance, and instead only checked the `currentNode` (which could be anything) for the existence of a `getBaseStreams` property.
This commit is contained in:
parent
67415bfabe
commit
67a1cfc1b1
3 changed files with 25 additions and 18 deletions
|
@ -94,6 +94,13 @@ class BaseStream {
|
|||
makeSubStream(start, length, dict = null) {
|
||||
unreachable("Abstract method `makeSubStream` called");
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Array | null}
|
||||
*/
|
||||
getBaseStreams() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export { BaseStream };
|
||||
|
|
|
@ -122,10 +122,7 @@ class DecodeStream extends BaseStream {
|
|||
}
|
||||
|
||||
getBaseStreams() {
|
||||
if (this.str && this.str.getBaseStreams) {
|
||||
return this.str.getBaseStreams();
|
||||
}
|
||||
return [];
|
||||
return this.str ? this.str.getBaseStreams() : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,13 +156,14 @@ class StreamsSequenceStream extends DecodeStream {
|
|||
}
|
||||
|
||||
getBaseStreams() {
|
||||
const baseStreams = [];
|
||||
const baseStreamsBuf = [];
|
||||
for (const stream of this.streams) {
|
||||
if (stream.getBaseStreams) {
|
||||
baseStreams.push(...stream.getBaseStreams());
|
||||
const baseStreams = stream.getBaseStreams();
|
||||
if (baseStreams) {
|
||||
baseStreamsBuf.push(...baseStreams);
|
||||
}
|
||||
}
|
||||
return baseStreams;
|
||||
return baseStreamsBuf.length > 0 ? baseStreamsBuf : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,18 +108,20 @@ class ObjectLoader {
|
|||
pendingRequests.push({ begin: ex.begin, end: ex.end });
|
||||
}
|
||||
}
|
||||
if (currentNode && currentNode.getBaseStreams) {
|
||||
if (isStream(currentNode)) {
|
||||
const baseStreams = currentNode.getBaseStreams();
|
||||
let foundMissingData = false;
|
||||
for (const stream of baseStreams) {
|
||||
if (stream.isDataLoaded) {
|
||||
continue;
|
||||
if (baseStreams) {
|
||||
let foundMissingData = false;
|
||||
for (const stream of baseStreams) {
|
||||
if (stream.isDataLoaded) {
|
||||
continue;
|
||||
}
|
||||
foundMissingData = true;
|
||||
pendingRequests.push({ begin: stream.start, end: stream.end });
|
||||
}
|
||||
if (foundMissingData) {
|
||||
nodesToRevisit.push(currentNode);
|
||||
}
|
||||
foundMissingData = true;
|
||||
pendingRequests.push({ begin: stream.start, end: stream.end });
|
||||
}
|
||||
if (foundMissingData) {
|
||||
nodesToRevisit.push(currentNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue