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: #47558
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Harshitha K P <harshitha014@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • 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.