mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +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
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue