Skip to content

Commit aaf669d

Browse files
jasnellMylesBorins
authored andcommitted
doc: document use of buffer.swap16() for utf16be
Fixes: #12813 PR-URL: #23747 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 6baba1d commit aaf669d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

doc/api/buffer.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,14 @@ buf2.swap16();
19331933
// Throws ERR_INVALID_BUFFER_SIZE
19341934
```
19351935

1936+
One convenient use of `buf.swap16()` is to perform a fast in-place conversion
1937+
between UTF-16 little-endian and UTF-16 big-endian:
1938+
1939+
```js
1940+
const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
1941+
buf.swap16(); // Convert to big-endian UTF-16 text.
1942+
```
1943+
19361944
### buf.swap32()
19371945
<!-- YAML
19381946
added: v5.10.0

0 commit comments

Comments
 (0)