Skip to content

Commit 9f20534

Browse files
Trotttargos
authored andcommitted
doc: shorten character encoding introduction
Keep the introduction for Buffers and character encodings short and to the point. The current introduction doesn't provide much in the way of useful additional information, but it is a bit confusing in its wording. ("such as" seems like it ought to refer to "encoded characters" but it actually refers to character encodings, which are not mentioned in the sentence. It may be arguable as to whether "hex-encoded" is in fact a character encoding, whether it should be stylized as "Hex-encoded" or not, and whether it should be spelled out as "Hexadecimal-encoded". None of that information is particularly useful to the end user at this point in the text. Omitting it simplifies and improves the documentation.) Additionally, the section is now wrapped to 80 characters. PR-URL: #19648 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
1 parent 94b28aa commit 9f20534

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

doc/api/buffer.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ changes:
149149
description: Removed the deprecated `raw` and `raws` encodings.
150150
-->
151151

152-
`Buffer` instances are commonly used to represent sequences of encoded characters
153-
such as UTF-8, UCS2, Base64, or even Hex-encoded data. It is possible to
154-
convert back and forth between `Buffer` instances and ordinary JavaScript strings
155-
by using an explicit character encoding.
152+
When string data is stored in or extracted out of a `Buffer` instance, a
153+
character encoding may be specified.
156154

157155
```js
158156
const buf = Buffer.from('hello world', 'ascii');
@@ -161,6 +159,11 @@ console.log(buf.toString('hex'));
161159
// Prints: 68656c6c6f20776f726c64
162160
console.log(buf.toString('base64'));
163161
// Prints: aGVsbG8gd29ybGQ=
162+
163+
console.log(Buffer.from('fhqwhgads', 'ascii'));
164+
// Prints: <Buffer 66 68 71 77 68 67 61 64 73>
165+
console.log(Buffer.from('fhqwhgads', 'ucs2'));
166+
// Prints: <Buffer 66 00 68 00 71 00 77 00 68 00 67 00 61 00 64 00 73 00>
164167
```
165168

166169
The character encodings currently supported by Node.js include:

0 commit comments

Comments
 (0)