diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 5c8b661e76e9cd..52f16f6d88909a 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -1058,6 +1058,28 @@ console.log(bufA.length); `Buffer.concat()` may also use the internal `Buffer` pool like [`Buffer.allocUnsafe()`][] does. +### Static method: `Buffer.copyFrom(view[, offset[, length]])` + + + +* `view` {TypedArray|DataView} The {TypedArray} or {DataView} to copy. +* `offset` {integer} The starting offset within `view`. **Default:**: `0`. +* `length` {integer} The number of elements from `view` to copy. + **Default:** `view\.length - offset`. + +Copies the underlying memory of `view` into a new `Buffer`. + +```js +const u16 = new Uint16Array([0, 0xffff]); +const buf = Buffer.copyFrom(u16, 0, 1); +u16[1] = 0; +console.log(buf.length); // 2 +console.log(buf[0]); // 255 +console.log(buf[1]); // 255 +``` + ### Static method: `Buffer.from(array)`