Merge pull request #21190 from Snuffleupagus/DecodeStream-abstract-readBlock

Add an abstract `readBlock` method in the `DecodeStream` class
This commit is contained in:
Jonas Jenwald 2026-04-29 14:19:10 +02:00 committed by GitHub
commit e2591b3fbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 20 deletions

View File

@ -13,10 +13,10 @@
* limitations under the License.
*/
import { shadow, unreachable } from "../shared/util.js";
import { DecodeStream } from "./decode_stream.js";
import { Dict } from "./primitives.js";
import { JBig2CCITTFaxImage } from "./jbig2_ccittFax.js";
import { shadow } from "../shared/util.js";
class CCITTFaxStream extends DecodeStream {
constructor(str, maybeLength, params) {
@ -46,10 +46,6 @@ class CCITTFaxStream extends DecodeStream {
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
readBlock() {
unreachable("CCITTFaxStream.readBlock");
}
get isImageStream() {
return true;
}

View File

@ -15,6 +15,7 @@
import { BaseStream } from "./base_stream.js";
import { Stream } from "./stream.js";
import { unreachable } from "../shared/util.js";
// Lots of DecodeStreams are created whose buffers are never used. For these
// we share a single empty buffer. This is (a) space-efficient and (b) avoids
@ -24,15 +25,20 @@ const emptyBuffer = new Uint8Array(0);
// Super class for the decoding streams.
class DecodeStream extends BaseStream {
buffer = emptyBuffer;
bufferLength = 0;
eof = false;
minBufferLength = 512;
pos = 0;
constructor(maybeMinBufferLength) {
super();
this._rawMinBufferLength = maybeMinBufferLength || 0;
this.pos = 0;
this.bufferLength = 0;
this.eof = false;
this.buffer = emptyBuffer;
this.minBufferLength = 512;
if (maybeMinBufferLength) {
// Compute the first power of two that is as big as maybeMinBufferLength.
while (this.minBufferLength < maybeMinBufferLength) {
@ -41,6 +47,10 @@ class DecodeStream extends BaseStream {
}
}
readBlock() {
unreachable("Abstract method `readBlock` called");
}
get isEmpty() {
while (!this.eof && this.bufferLength === 0) {
this.readBlock();

View File

@ -13,11 +13,11 @@
* limitations under the License.
*/
import { shadow, unreachable } from "../shared/util.js";
import { BaseStream } from "./base_stream.js";
import { DecodeStream } from "./decode_stream.js";
import { Dict } from "./primitives.js";
import { JBig2CCITTFaxImage } from "./jbig2_ccittFax.js";
import { shadow } from "../shared/util.js";
/**
* For JBIG2's we use a library to decode these images and
@ -43,10 +43,6 @@ class Jbig2Stream extends DecodeStream {
// directly insert all of its data into `this.buffer`.
}
readBlock() {
unreachable("Jbig2Stream.readBlock");
}
get isAsyncDecoder() {
return true;
}

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
import { shadow, unreachable } from "../shared/util.js";
import { DecodeStream } from "./decode_stream.js";
import { JpxImage } from "./jpx.js";
import { shadow } from "../shared/util.js";
/**
* For JPEG 2000's we use a library to decode these images and
@ -41,10 +41,6 @@ class JpxStream extends DecodeStream {
// directly insert all of its data into `this.buffer`.
}
readBlock(decoderOptions) {
unreachable("JpxStream.readBlock");
}
get isAsyncDecoder() {
return true;
}