Skip to content

Commit

Permalink
squash: address requests for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Mar 29, 2018
1 parent 305633e commit 6e7cbe3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ changes:
description: Removed the deprecated `raw` and `raws` encodings.
-->

A character encoding may be specified when converting between a string and a
`Buffer`.
When string data is stored in or extracted out of a `Buffer` instance, a
character encoding may be specified.

```js
const buf = Buffer.from('hello world', 'ascii');
Expand All @@ -159,6 +159,11 @@ console.log(buf.toString('hex'));
// Prints: 68656c6c6f20776f726c64
console.log(buf.toString('base64'));
// Prints: aGVsbG8gd29ybGQ=

console.log(Buffer.from('fhqwhgads', 'ascii'));
// Prints: <Buffer 66 68 71 77 68 67 61 64 73>
console.log(Buffer.from('fhqwhgads', 'ucs2'));
// Prints: <Buffer 66 00 68 00 71 00 77 00 68 00 67 00 61 00 64 00 73 00>
```

The character encodings currently supported by Node.js include:
Expand Down

0 comments on commit 6e7cbe3

Please sign in to comment.