[Reporting] Improve _read code in ContentStream (#113237) (#113830)

Co-authored-by: Thomas Watson <w@tson.dk>
This commit is contained in:
Kibana Machine 2021-10-04 17:00:08 -04:00 committed by GitHub
parent dad2009acd
commit 5c794e0bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,28 +179,27 @@ export class ContentStream extends Duplex {
return this.jobSize != null && this.bytesRead >= this.jobSize;
}
async _read() {
try {
const content = this.chunksRead ? await this.readChunk() : await this.readHead();
if (!content) {
this.logger.debug(`Chunk is empty.`);
this.push(null);
return;
}
_read() {
(this.chunksRead ? this.readChunk() : this.readHead())
.then((content) => {
if (!content) {
this.logger.debug(`Chunk is empty.`);
this.push(null);
return;
}
const buffer = this.decode(content);
const buffer = this.decode(content);
this.push(buffer);
this.chunksRead++;
this.bytesRead += buffer.byteLength;
this.push(buffer);
this.chunksRead++;
this.bytesRead += buffer.byteLength;
if (this.isRead()) {
this.logger.debug(`Read ${this.bytesRead} of ${this.jobSize} bytes.`);
this.push(null);
}
} catch (error) {
this.destroy(error);
}
if (this.isRead()) {
this.logger.debug(`Read ${this.bytesRead} of ${this.jobSize} bytes.`);
this.push(null);
}
})
.catch((err) => this.destroy(err));
}
private async removeChunks() {