MCPcopy Index your code
hub / github.com/nodejs/node / toArrayBuffer

Function toArrayBuffer

lib/internal/streams/iter/consumers.js:163–181  ·  view source on GitHub ↗

* Convert a Uint8Array to its backing ArrayBuffer, slicing if necessary. * Handles both ArrayBuffer and SharedArrayBuffer backing stores. * @param {Uint8Array} data * @returns {ArrayBuffer|SharedArrayBuffer}

(data)

Source from the content-addressed store, hash-verified

161 * @returns {ArrayBuffer|SharedArrayBuffer}
162 */
163function toArrayBuffer(data) {
164 const byteOffset = TypedArrayPrototypeGetByteOffset(data);
165 const byteLength = TypedArrayPrototypeGetByteLength(data);
166 const buffer = TypedArrayPrototypeGetBuffer(data);
167 // SharedArrayBuffer is not available in primordials, so use
168 // direct property access for its byteLength and slice.
169 if (isSharedArrayBuffer(buffer)) {
170 if (byteOffset === 0 && byteLength === buffer.byteLength) {
171 return buffer;
172 }
173 return buffer.slice(byteOffset, byteOffset + byteLength);
174 }
175 if (byteOffset === 0 &&
176 byteLength === ArrayBufferPrototypeGetByteLength(buffer)) {
177 return buffer;
178 }
179 return ArrayBufferPrototypeSlice(buffer, byteOffset,
180 byteOffset + byteLength);
181}
182
183// =============================================================================
184// Shared option validation

Callers 2

arrayBufferSyncFunction · 0.70
arrayBufferFunction · 0.70

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…