Skip to content

Commit

Permalink
doc: add missing setEncoding call in ESM example
Browse files Browse the repository at this point in the history
Adding `setEncoding()` ensures that the example handles characters
split across chunk boundaries well.

PR-URL: nodejs#47558
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
  • Loading branch information
addaleax authored and MoLow committed Jul 6, 2023
1 parent fa447b5 commit d40bcdd
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ export function load(url, context, nextLoad) {
return new Promise((resolve, reject) => {
get(url, (res) => {
let data = '';
res.setEncoding('utf8');
res.on('data', (chunk) => data += chunk);
res.on('end', () => resolve({
// This example assumes all network-provided JavaScript is ES module
Expand Down

0 comments on commit d40bcdd

Please sign in to comment.