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 Apr 14, 2023
1 parent 503d838 commit cad0ae7
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 @@ -1058,6 +1058,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 cad0ae7

Please sign in to comment.