Convert src/core/lzw_stream.js
to use standard classes
This commit is contained in:
parent
1f9b134c6a
commit
1f0685cee6
@ -15,9 +15,10 @@
|
|||||||
|
|
||||||
import { DecodeStream } from "./stream.js";
|
import { DecodeStream } from "./stream.js";
|
||||||
|
|
||||||
const LZWStream = (function LZWStreamClosure() {
|
class LZWStream extends DecodeStream {
|
||||||
// eslint-disable-next-line no-shadow
|
constructor(str, maybeLength, earlyChange) {
|
||||||
function LZWStream(str, maybeLength, earlyChange) {
|
super(maybeLength);
|
||||||
|
|
||||||
this.str = str;
|
this.str = str;
|
||||||
this.dict = str.dict;
|
this.dict = str.dict;
|
||||||
this.cachedData = 0;
|
this.cachedData = 0;
|
||||||
@ -39,13 +40,9 @@ const LZWStream = (function LZWStreamClosure() {
|
|||||||
lzwState.dictionaryLengths[i] = 1;
|
lzwState.dictionaryLengths[i] = 1;
|
||||||
}
|
}
|
||||||
this.lzwState = lzwState;
|
this.lzwState = lzwState;
|
||||||
|
|
||||||
DecodeStream.call(this, maybeLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LZWStream.prototype = Object.create(DecodeStream.prototype);
|
readBits(n) {
|
||||||
|
|
||||||
LZWStream.prototype.readBits = function LZWStream_readBits(n) {
|
|
||||||
let bitsCached = this.bitsCached;
|
let bitsCached = this.bitsCached;
|
||||||
let cachedData = this.cachedData;
|
let cachedData = this.cachedData;
|
||||||
while (bitsCached < n) {
|
while (bitsCached < n) {
|
||||||
@ -61,9 +58,9 @@ const LZWStream = (function LZWStreamClosure() {
|
|||||||
this.cachedData = cachedData;
|
this.cachedData = cachedData;
|
||||||
this.lastCode = null;
|
this.lastCode = null;
|
||||||
return (cachedData >>> bitsCached) & ((1 << n) - 1);
|
return (cachedData >>> bitsCached) & ((1 << n) - 1);
|
||||||
};
|
}
|
||||||
|
|
||||||
LZWStream.prototype.readBlock = function LZWStream_readBlock() {
|
readBlock() {
|
||||||
const blockSize = 512,
|
const blockSize = 512,
|
||||||
decodedSizeDelta = blockSize;
|
decodedSizeDelta = blockSize;
|
||||||
let estimatedDecodedSize = blockSize * 2;
|
let estimatedDecodedSize = blockSize * 2;
|
||||||
@ -147,9 +144,7 @@ const LZWStream = (function LZWStreamClosure() {
|
|||||||
lzwState.currentSequenceLength = currentSequenceLength;
|
lzwState.currentSequenceLength = currentSequenceLength;
|
||||||
|
|
||||||
this.bufferLength = currentBufferLength;
|
this.bufferLength = currentBufferLength;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return LZWStream;
|
|
||||||
})();
|
|
||||||
|
|
||||||
export { LZWStream };
|
export { LZWStream };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user