Enable the no-var rule in the src/core/src/core/lzw_stream.js file

This commit is contained in:
Jonas Jenwald 2021-04-27 12:58:48 +02:00
parent 6c1a321500
commit 1f9b134c6a

View File

@ -12,11 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-var */
import { DecodeStream } from "./stream.js"; import { DecodeStream } from "./stream.js";
var LZWStream = (function LZWStreamClosure() { const LZWStream = (function LZWStreamClosure() {
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
function LZWStream(str, maybeLength, earlyChange) { function LZWStream(str, maybeLength, earlyChange) {
this.str = str; this.str = str;
@ -24,8 +23,8 @@ var LZWStream = (function LZWStreamClosure() {
this.cachedData = 0; this.cachedData = 0;
this.bitsCached = 0; this.bitsCached = 0;
var maxLzwDictionarySize = 4096; const maxLzwDictionarySize = 4096;
var lzwState = { const lzwState = {
earlyChange, earlyChange,
codeLength: 9, codeLength: 9,
nextCode: 258, nextCode: 258,
@ -35,7 +34,7 @@ var LZWStream = (function LZWStreamClosure() {
currentSequence: new Uint8Array(maxLzwDictionarySize), currentSequence: new Uint8Array(maxLzwDictionarySize),
currentSequenceLength: 0, currentSequenceLength: 0,
}; };
for (var i = 0; i < 256; ++i) { for (let i = 0; i < 256; ++i) {
lzwState.dictionaryValues[i] = i; lzwState.dictionaryValues[i] = i;
lzwState.dictionaryLengths[i] = 1; lzwState.dictionaryLengths[i] = 1;
} }
@ -47,10 +46,10 @@ var LZWStream = (function LZWStreamClosure() {
LZWStream.prototype = Object.create(DecodeStream.prototype); LZWStream.prototype = Object.create(DecodeStream.prototype);
LZWStream.prototype.readBits = function LZWStream_readBits(n) { LZWStream.prototype.readBits = function LZWStream_readBits(n) {
var bitsCached = this.bitsCached; let bitsCached = this.bitsCached;
var cachedData = this.cachedData; let cachedData = this.cachedData;
while (bitsCached < n) { while (bitsCached < n) {
var c = this.str.getByte(); const c = this.str.getByte();
if (c === -1) { if (c === -1) {
this.eof = true; this.eof = true;
return null; return null;
@ -65,33 +64,33 @@ var LZWStream = (function LZWStreamClosure() {
}; };
LZWStream.prototype.readBlock = function LZWStream_readBlock() { LZWStream.prototype.readBlock = function LZWStream_readBlock() {
var blockSize = 512; const blockSize = 512,
var estimatedDecodedSize = blockSize * 2,
decodedSizeDelta = blockSize; decodedSizeDelta = blockSize;
var i, j, q; let estimatedDecodedSize = blockSize * 2;
let i, j, q;
var lzwState = this.lzwState; const lzwState = this.lzwState;
if (!lzwState) { if (!lzwState) {
return; // eof was found return; // eof was found
} }
var earlyChange = lzwState.earlyChange; const earlyChange = lzwState.earlyChange;
var nextCode = lzwState.nextCode; let nextCode = lzwState.nextCode;
var dictionaryValues = lzwState.dictionaryValues; const dictionaryValues = lzwState.dictionaryValues;
var dictionaryLengths = lzwState.dictionaryLengths; const dictionaryLengths = lzwState.dictionaryLengths;
var dictionaryPrevCodes = lzwState.dictionaryPrevCodes; const dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
var codeLength = lzwState.codeLength; let codeLength = lzwState.codeLength;
var prevCode = lzwState.prevCode; let prevCode = lzwState.prevCode;
var currentSequence = lzwState.currentSequence; const currentSequence = lzwState.currentSequence;
var currentSequenceLength = lzwState.currentSequenceLength; let currentSequenceLength = lzwState.currentSequenceLength;
var decodedLength = 0; let decodedLength = 0;
var currentBufferLength = this.bufferLength; let currentBufferLength = this.bufferLength;
var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize); let buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
for (i = 0; i < blockSize; i++) { for (i = 0; i < blockSize; i++) {
var code = this.readBits(codeLength); const code = this.readBits(codeLength);
var hasPrev = currentSequenceLength > 0; const hasPrev = currentSequenceLength > 0;
if (code < 256) { if (code < 256) {
currentSequence[0] = code; currentSequence[0] = code;
currentSequenceLength = 1; currentSequenceLength = 1;