Use stream for whatever substrem in stream classes
and add a method in order to get the original stream. When writing an existing stream it'll help to have the original one instead of the filtered one.
This commit is contained in:
parent
928a758811
commit
05f368056d
@ -25,7 +25,7 @@ class Ascii85Stream extends DecodeStream {
|
||||
}
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
this.input = new Uint8Array(5);
|
||||
}
|
||||
@ -35,7 +35,7 @@ class Ascii85Stream extends DecodeStream {
|
||||
const Z_LOWER_CHAR = 0x7a; // 'z'
|
||||
const EOF = -1;
|
||||
|
||||
const str = this.str;
|
||||
const str = this.stream;
|
||||
|
||||
let c = str.getByte();
|
||||
while (isWhiteSpace(c)) {
|
||||
|
||||
@ -24,7 +24,7 @@ class AsciiHexStream extends DecodeStream {
|
||||
}
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
this.firstDigit = -1;
|
||||
@ -32,7 +32,7 @@ class AsciiHexStream extends DecodeStream {
|
||||
|
||||
readBlock() {
|
||||
const UPSTREAM_BLOCK_SIZE = 8000;
|
||||
const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
|
||||
const bytes = this.stream.getBytes(UPSTREAM_BLOCK_SIZE);
|
||||
if (!bytes.length) {
|
||||
this.eof = true;
|
||||
return;
|
||||
|
||||
@ -137,6 +137,10 @@ class BaseStream {
|
||||
getBaseStreams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
getOriginalStream() {
|
||||
return this.stream?.getOriginalStream() || this;
|
||||
}
|
||||
}
|
||||
|
||||
export { BaseStream };
|
||||
|
||||
@ -21,7 +21,7 @@ class CCITTFaxStream extends DecodeStream {
|
||||
constructor(str, maybeLength, params) {
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
if (!(params instanceof Dict)) {
|
||||
|
||||
@ -129,7 +129,7 @@ class DecodeStream extends BaseStream {
|
||||
}
|
||||
|
||||
getBaseStreams() {
|
||||
return this.str ? this.str.getBaseStreams() : null;
|
||||
return this.stream ? this.stream.getBaseStreams() : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ class DecryptStream extends DecodeStream {
|
||||
constructor(str, maybeLength, decrypt) {
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
this.decrypt = decrypt;
|
||||
this.nextChunk = null;
|
||||
@ -33,14 +33,14 @@ class DecryptStream extends DecodeStream {
|
||||
if (this.initialized) {
|
||||
chunk = this.nextChunk;
|
||||
} else {
|
||||
chunk = this.str.getBytes(chunkSize);
|
||||
chunk = this.stream.getBytes(chunkSize);
|
||||
this.initialized = true;
|
||||
}
|
||||
if (!chunk?.length) {
|
||||
this.eof = true;
|
||||
return;
|
||||
}
|
||||
this.nextChunk = this.str.getBytes(chunkSize);
|
||||
this.nextChunk = this.stream.getBytes(chunkSize);
|
||||
const hasMoreData = this.nextChunk?.length > 0;
|
||||
|
||||
const decrypt = this.decrypt;
|
||||
|
||||
@ -125,7 +125,7 @@ class FlateStream extends DecodeStream {
|
||||
constructor(str, maybeLength) {
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
const cmf = str.getByte();
|
||||
@ -161,8 +161,8 @@ class FlateStream extends DecodeStream {
|
||||
}
|
||||
|
||||
async asyncGetBytes() {
|
||||
this.str.reset();
|
||||
const bytes = this.str.getBytes();
|
||||
this.stream.reset();
|
||||
const bytes = this.stream.getBytes();
|
||||
|
||||
try {
|
||||
const { readable, writable } = new DecompressionStream("deflate");
|
||||
@ -200,11 +200,11 @@ class FlateStream extends DecodeStream {
|
||||
// decoder.
|
||||
// We already get the bytes from the underlying stream, so we just reuse
|
||||
// them to avoid get them again.
|
||||
this.str = new Stream(
|
||||
this.stream = new Stream(
|
||||
bytes,
|
||||
2 /* = header size (see ctor) */,
|
||||
bytes.length,
|
||||
this.str.dict
|
||||
this.stream.dict
|
||||
);
|
||||
this.reset();
|
||||
return null;
|
||||
@ -216,7 +216,7 @@ class FlateStream extends DecodeStream {
|
||||
}
|
||||
|
||||
getBits(bits) {
|
||||
const str = this.str;
|
||||
const str = this.stream;
|
||||
let codeSize = this.codeSize;
|
||||
let codeBuf = this.codeBuf;
|
||||
|
||||
@ -236,7 +236,7 @@ class FlateStream extends DecodeStream {
|
||||
}
|
||||
|
||||
getCode(table) {
|
||||
const str = this.str;
|
||||
const str = this.stream;
|
||||
const codes = table[0];
|
||||
const maxLen = table[1];
|
||||
let codeSize = this.codeSize;
|
||||
@ -312,7 +312,7 @@ class FlateStream extends DecodeStream {
|
||||
|
||||
readBlock() {
|
||||
let buffer, hdr, len;
|
||||
const str = this.str;
|
||||
const str = this.stream;
|
||||
// read block header
|
||||
try {
|
||||
hdr = this.getBits(3);
|
||||
|
||||
@ -19,7 +19,7 @@ class LZWStream extends DecodeStream {
|
||||
constructor(str, maybeLength, earlyChange) {
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
this.cachedData = 0;
|
||||
this.bitsCached = 0;
|
||||
@ -46,7 +46,7 @@ class LZWStream extends DecodeStream {
|
||||
let bitsCached = this.bitsCached;
|
||||
let cachedData = this.cachedData;
|
||||
while (bitsCached < n) {
|
||||
const c = this.str.getByte();
|
||||
const c = this.stream.getByte();
|
||||
if (c === -1) {
|
||||
this.eof = true;
|
||||
return null;
|
||||
|
||||
@ -35,7 +35,7 @@ class PredictorStream extends DecodeStream {
|
||||
|
||||
this.readBlock = predictor === 2 ? this.readBlockTiff : this.readBlockPng;
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
const colors = (this.colors = params.get("Colors") || 1);
|
||||
@ -57,7 +57,7 @@ class PredictorStream extends DecodeStream {
|
||||
const bits = this.bits;
|
||||
const colors = this.colors;
|
||||
|
||||
const rawBytes = this.str.getBytes(rowBytes);
|
||||
const rawBytes = this.stream.getBytes(rowBytes);
|
||||
this.eof = !rawBytes.length;
|
||||
if (this.eof) {
|
||||
return;
|
||||
@ -138,8 +138,8 @@ class PredictorStream extends DecodeStream {
|
||||
const rowBytes = this.rowBytes;
|
||||
const pixBytes = this.pixBytes;
|
||||
|
||||
const predictor = this.str.getByte();
|
||||
const rawBytes = this.str.getBytes(rowBytes);
|
||||
const predictor = this.stream.getByte();
|
||||
const rawBytes = this.stream.getBytes(rowBytes);
|
||||
this.eof = !rawBytes.length;
|
||||
if (this.eof) {
|
||||
return;
|
||||
|
||||
@ -19,7 +19,7 @@ class RunLengthStream extends DecodeStream {
|
||||
constructor(str, maybeLength) {
|
||||
super(maybeLength);
|
||||
|
||||
this.str = str;
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ class RunLengthStream extends DecodeStream {
|
||||
// and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
|
||||
// (in addition to the second byte from the header), n = 129 through 255 -
|
||||
// duplicate the second byte from the header (257 - n) times, n = 128 - end.
|
||||
const repeatHeader = this.str.getBytes(2);
|
||||
const repeatHeader = this.stream.getBytes(2);
|
||||
if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
|
||||
this.eof = true;
|
||||
return;
|
||||
@ -42,7 +42,7 @@ class RunLengthStream extends DecodeStream {
|
||||
buffer = this.ensureBuffer(bufferLength + n + 1);
|
||||
buffer[bufferLength++] = repeatHeader[1];
|
||||
if (n > 0) {
|
||||
const source = this.str.getBytes(n);
|
||||
const source = this.stream.getBytes(n);
|
||||
buffer.set(source, bufferLength);
|
||||
bufferLength += n;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user