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
@ -94,6 +94,13 @@ class BaseStream {
|
|||||||
makeSubStream(start, length, dict = null) {
|
makeSubStream(start, length, dict = null) {
|
||||||
unreachable("Abstract method `makeSubStream` called");
|
unreachable("Abstract method `makeSubStream` called");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Array | null}
|
||||||
|
*/
|
||||||
|
getBaseStreams() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { BaseStream };
|
export { BaseStream };
|
||||||
|
@ -122,10 +122,7 @@ class DecodeStream extends BaseStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getBaseStreams() {
|
getBaseStreams() {
|
||||||
if (this.str && this.str.getBaseStreams) {
|
return this.str ? this.str.getBaseStreams() : null;
|
||||||
return this.str.getBaseStreams();
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,13 +156,14 @@ class StreamsSequenceStream extends DecodeStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getBaseStreams() {
|
getBaseStreams() {
|
||||||
const baseStreams = [];
|
const baseStreamsBuf = [];
|
||||||
for (const stream of this.streams) {
|
for (const stream of this.streams) {
|
||||||
if (stream.getBaseStreams) {
|
const baseStreams = stream.getBaseStreams();
|
||||||
baseStreams.push(...stream.getBaseStreams());
|
if (baseStreams) {
|
||||||
|
baseStreamsBuf.push(...baseStreams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return baseStreams;
|
return baseStreamsBuf.length > 0 ? baseStreamsBuf : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +108,9 @@ class ObjectLoader {
|
|||||||
pendingRequests.push({ begin: ex.begin, end: ex.end });
|
pendingRequests.push({ begin: ex.begin, end: ex.end });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentNode && currentNode.getBaseStreams) {
|
if (isStream(currentNode)) {
|
||||||
const baseStreams = currentNode.getBaseStreams();
|
const baseStreams = currentNode.getBaseStreams();
|
||||||
|
if (baseStreams) {
|
||||||
let foundMissingData = false;
|
let foundMissingData = false;
|
||||||
for (const stream of baseStreams) {
|
for (const stream of baseStreams) {
|
||||||
if (stream.isDataLoaded) {
|
if (stream.isDataLoaded) {
|
||||||
@ -122,6 +123,7 @@ class ObjectLoader {
|
|||||||
nodesToRevisit.push(currentNode);
|
nodesToRevisit.push(currentNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addChildren(currentNode, nodesToVisit);
|
addChildren(currentNode, nodesToVisit);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user