Slight nit, in both cases you're concating chunk directly to string (converting it to string implicitly) which causes problems with encodings like UTF8 as one symbol spans more than one char. Better to use Buffer.concat(chunk).
-
-
-
I wonder if we should update the stream examples in the Node.js docs. `data += chunk` seems pretty common on https://nodejs.org/api/stream.html . +
@matteocollina - 6 more replies
New conversation -
-
-
How to handle errors here?
-
Wrap it in try/catch.
End of conversation
New conversation -
-
-
important question! What color/theme are you using here?
-
It’s the Dark (Alternate) theme from https://romannurik.github.io/SlidesCodeHighlighter/ ….
End of conversation
New conversation -
-
-
mmmh. Not entirely clear to me, how does the for await know how to handle `.on('data', ...)` since it's not a promise?
-
It doesn’t handle that at all. The secret sauce is `Symbol.asyncIterator`: https://nodejs.org/api/stream.html#stream_readable_symbol_asynciterator …
End of conversation
New conversation -
-
-
I wonder why not console log inside the for await? Doesnt this wait till the full stream is loaded into memory??
-
That would log each chunk.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.