Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: replace var with let/const #30394

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const codes = {
};

const ckeys = ObjectKeys(codes);
for (var ck = 0; ck < ckeys.length; ck++) {
var ckey = ckeys[ck];
for (let ck = 0; ck < ckeys.length; ck++) {
const ckey = ckeys[ck];
codes[codes[ckey]] = ckey;
}

Expand Down Expand Up @@ -131,14 +131,14 @@ function zlibBufferOnError(err) {
}

function zlibBufferOnEnd() {
var buf;
var err;
let buf;
let err;
if (this.nread >= kMaxLength) {
err = new ERR_BUFFER_TOO_LARGE();
} else if (this.nread === 0) {
buf = Buffer.alloc(0);
} else {
var bufs = this.buffers;
const bufs = this.buffers;
buf = (bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread));
}
this.close();
Expand Down Expand Up @@ -230,7 +230,7 @@ const checkRangesOrGetDefault = hideStackFrames(

// The base class for all Zlib-style streams.
function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
var chunkSize = Z_DEFAULT_CHUNK;
let chunkSize = Z_DEFAULT_CHUNK;
// The ZlibBase class is not exported to user land, the mode should only be
// passed in by us.
assert(typeof mode === 'number');
Expand Down Expand Up @@ -379,7 +379,7 @@ ZlibBase.prototype._destroy = function(err, callback) {
};

ZlibBase.prototype._transform = function(chunk, encoding, cb) {
var flushFlag = this._defaultFlushFlag;
let flushFlag = this._defaultFlushFlag;
// We use a 'fake' zero-length chunk to carry information about flushes from
// the public API to the actual stream implementation.
if (typeof chunk[kFlushFlag] === 'number') {
Expand All @@ -403,22 +403,22 @@ ZlibBase.prototype._processChunk = function(chunk, flushFlag, cb) {
};

function processChunkSync(self, chunk, flushFlag) {
var availInBefore = chunk.byteLength;
var availOutBefore = self._chunkSize - self._outOffset;
var inOff = 0;
var availOutAfter;
var availInAfter;

var buffers = null;
var nread = 0;
var inputRead = 0;
let availInBefore = chunk.byteLength;
let availOutBefore = self._chunkSize - self._outOffset;
let inOff = 0;
let availOutAfter;
let availInAfter;

let buffers = null;
let nread = 0;
let inputRead = 0;
const state = self._writeState;
const handle = self._handle;
var buffer = self._outBuffer;
var offset = self._outOffset;
let buffer = self._outBuffer;
let offset = self._outOffset;
const chunkSize = self._chunkSize;

var error;
let error;
self.on('error', function onError(er) {
error = er;
});
Expand All @@ -437,12 +437,12 @@ function processChunkSync(self, chunk, flushFlag) {
availOutAfter = state[0];
availInAfter = state[1];

var inDelta = (availInBefore - availInAfter);
const inDelta = (availInBefore - availInAfter);
inputRead += inDelta;

var have = availOutBefore - availOutAfter;
const have = availOutBefore - availOutAfter;
if (have > 0) {
var out = buffer.slice(offset, offset + have);
const out = buffer.slice(offset, offset + have);
offset += have;
if (!buffers)
buffers = [out];
Expand Down Expand Up @@ -527,7 +527,7 @@ function processCallback() {

const have = handle.availOutBefore - availOutAfter;
if (have > 0) {
var out = self._outBuffer.slice(self._outOffset, self._outOffset + have);
const out = self._outBuffer.slice(self._outOffset, self._outOffset + have);
self._outOffset += have;
self.push(out);
} else {
Expand Down Expand Up @@ -599,11 +599,11 @@ const zlibDefaultOpts = {
// Base class for all streams actually backed by zlib and using zlib-specific
// parameters.
function Zlib(opts, mode) {
var windowBits = Z_DEFAULT_WINDOWBITS;
var level = Z_DEFAULT_COMPRESSION;
var memLevel = Z_DEFAULT_MEMLEVEL;
var strategy = Z_DEFAULT_STRATEGY;
var dictionary;
let windowBits = Z_DEFAULT_WINDOWBITS;
let level = Z_DEFAULT_COMPRESSION;
let memLevel = Z_DEFAULT_MEMLEVEL;
let strategy = Z_DEFAULT_STRATEGY;
let dictionary;

if (opts) {
// windowBits is special. On the compression side, 0 is an invalid value.
Expand Down Expand Up @@ -912,8 +912,8 @@ ObjectDefineProperties(module.exports, {
// These should be considered deprecated
// expose all the zlib constants
const bkeys = ObjectKeys(constants);
for (var bk = 0; bk < bkeys.length; bk++) {
var bkey = bkeys[bk];
for (let bk = 0; bk < bkeys.length; bk++) {
const bkey = bkeys[bk];
if (bkey.startsWith('BROTLI')) continue;
ObjectDefineProperty(module.exports, bkey, {
enumerable: false, value: constants[bkey], writable: false
Expand Down