Fix some Streams weirdness

Pointed out by @urkerab in e91c4c5260

I'm confused it ever worked in the past.

I also added `Symbol.asyncIterator` to make `for await` work correctly.
I'm still very annoyed by `Symbol`. Especially since the spec saw no
reason not to name the other function `next`, but calling it
`asyncIterator` instead of `[Symbol.asyncIterator] was too much of a
risk??? Complete bullshit that does nothing but break backwards
compatibility.
This commit is contained in:
Guangcong Luo 2020-08-15 14:32:21 -07:00
parent 4cbf905ec8
commit 001f98b4f2

View File

@ -248,7 +248,7 @@ export class ReadStream {
byteCount = null;
}
await this.loadIntoBuffer(byteCount, true);
const out = this.peek(byteCount, encoding) as string | null;
const out = await this.peek(byteCount, encoding);
if (byteCount === null || byteCount >= this.bufSize) {
this.bufStart = 0;
this.bufEnd = 0;
@ -260,7 +260,7 @@ export class ReadStream {
async readBuffer(byteCount: number | null = null) {
await this.loadIntoBuffer(byteCount, true);
const out = this.peekBuffer(byteCount);
const out = await this.peekBuffer(byteCount);
if (byteCount === null || byteCount >= this.bufSize) {
this.bufStart = 0;
this.bufEnd = 0;
@ -650,6 +650,8 @@ export class ObjectReadStream<T> {
return this._destroy();
}
// eslint-disable-next-line no-restricted-globals
[Symbol.asyncIterator]() { return this; }
async next() {
const value = await this.read();
return {value, done: value === null};