From f82b80edf4e7d5effcc17689f614c3233c8aa168 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 6 Dec 2021 15:37:54 +0100 Subject: [PATCH] refactor totalBytesConsumed -> bytesToFlush --- x-pack/plugins/reporting/server/lib/content_stream.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/reporting/server/lib/content_stream.ts b/x-pack/plugins/reporting/server/lib/content_stream.ts index a02dc22c627b0..2aec56ac19d4b 100644 --- a/x-pack/plugins/reporting/server/lib/content_stream.ts +++ b/x-pack/plugins/reporting/server/lib/content_stream.ts @@ -254,7 +254,7 @@ export class ContentStream extends Duplex { private async flush(size = this.bytesBuffered) { const buffersToFlush: Buffer[] = []; let partiallyFlushedBuffer: undefined | Buffer; - let totalBytesConsumed = 0; + let bytesToFlush = 0; /* Loop over each buffer, keeping track of how many bytes we have added @@ -273,14 +273,14 @@ export class ContentStream extends Duplex { need this code to be as performant as possible. */ for (const buffer of this.buffers) { - const remainder = size - totalBytesConsumed; + const remainder = size - bytesToFlush; if (remainder < 0) { break; } const chunkedBuffer = remainder > 0 ? buffer.slice(0, remainder) : buffer; buffersToFlush.push(chunkedBuffer); - totalBytesConsumed += chunkedBuffer.byteLength; + bytesToFlush += chunkedBuffer.byteLength; // Did we add a partial buffer? Cache the rest and stop looping. if (buffer.byteLength > remainder) { @@ -316,7 +316,7 @@ export class ContentStream extends Duplex { ? [partiallyFlushedBuffer, ...this.buffers.slice(buffersToFlush.length)] : this.buffers.slice(Math.max(buffersToFlush.length - 1, 1)); - this.bytesBuffered -= totalBytesConsumed; + this.bytesBuffered -= bytesToFlush; } private async flushAllFullChunks() {