Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix misleading ASCII comments #11657

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ const buf3 = Buffer.allocUnsafe(10);
// Creates a Buffer containing [0x1, 0x2, 0x3].
const buf4 = Buffer.from([1, 2, 3]);

// Creates a Buffer containing ASCII bytes [0x74, 0x65, 0x73, 0x74].
const buf5 = Buffer.from('test');

// Creates a Buffer containing UTF-8 bytes [0x74, 0xc3, 0xa9, 0x73, 0x74].
const buf6 = Buffer.from('tést', 'utf8');
const buf5 = Buffer.from('tést');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this example? I think I can see where this is coming from, but it might be better to just replace ASCII with ASCII/UTF-8 in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that it's more consistent with the other examples in the doc, and also shows the difference between the two encodings that will affect the output ('test' is the same in ascii and utf8 but not 'tést'). That may or may not be important

Just changing the text to ASCII/UTF-8 is still an improvement but I think this example is clearer.


// Creates a Buffer containing Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
const buf6 = Buffer.from('tést', 'latin-1');
```

## `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
Expand Down Expand Up @@ -331,7 +331,7 @@ Allocates a new `Buffer` using an `array` of octets.
Example:

```js
// Creates a new Buffer containing the ASCII bytes of the string 'buffer'
// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'
const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
```

Expand Down Expand Up @@ -787,7 +787,7 @@ Allocates a new `Buffer` using an `array` of octets.
Example:

```js
// Creates a new Buffer containing ASCII bytes of the string 'buffer'
// Creates a new Buffer containing UTF-8 bytes of the string 'buffer'
const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
```

Expand Down