doc: document use of buffer.swap16() for utf16be

Fixes: https://github.com/nodejs/node/issues/12813

PR-URL: https://github.com/nodejs/node/pull/23747
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
James M Snell 2018-10-18 18:22:46 -07:00
parent bef24e163a
commit ad61550646
No known key found for this signature in database
GPG Key ID: 7341B15C070877AC

View File

@ -1936,6 +1936,14 @@ buf2.swap16();
// Throws ERR_INVALID_BUFFER_SIZE
```
One convenient use of `buf.swap16()` is to perform a fast in-place conversion
between UTF-16 little-endian and UTF-16 big-endian:
```js
const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
buf.swap16(); // Convert to big-endian UTF-16 text.
```
### buf.swap32()
<!-- YAML
added: v5.10.0