From 65daaff0369d4fbbedcb181ea04089a8df827ee0 Mon Sep 17 00:00:00 2001 From: Sam Sudar Date: Fri, 30 Jun 2017 22:14:16 -0700 Subject: [PATCH] Add slice for converting to ArrayBuffer The .buffer property is an ArrayBuffer, but it is not necessarily the same length as the original buffer. This adds further documentation to the README to flesh out converting a Buffer to an ArrayBuffer. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6acfd22..e925100 100644 --- a/README.md +++ b/README.md @@ -138,9 +138,13 @@ var buffer = Buffer.from(arrayBuffer) To convert a `Buffer` to an `ArrayBuffer`, use the `.buffer` property (which is present on all `Uint8Array` objects): ```js -var arrayBuffer = buffer.buffer +var arrayBuffer = buffer.buffer.slice( + buffer.byteOffset, buffer.byteOffset + buffer.byteLength +) ``` +Alternatively, use the [`to-arraybuffer`](https://www.npmjs.com/package/to-arraybuffer) module. + ## performance See perf tests in `/perf`. -- 2.34.1