MCPcopy
hub / github.com/feross/buffer / fromArrayBuffer

Function fromArrayBuffer

index.js:273–295  ·  view source on GitHub ↗
(array, byteOffset, length)

Source from the content-addressed store, hash-verified

271}
272
273function fromArrayBuffer (array, byteOffset, length) {
274 if (byteOffset < 0 || array.byteLength < byteOffset) {
275 throw new RangeError('"offset" is outside of buffer bounds')
276 }
277
278 if (array.byteLength < byteOffset + (length || 0)) {
279 throw new RangeError('"length" is outside of buffer bounds')
280 }
281
282 let buf
283 if (byteOffset === undefined && length === undefined) {
284 buf = new Uint8Array(array)
285 } else if (length === undefined) {
286 buf = new Uint8Array(array, byteOffset)
287 } else {
288 buf = new Uint8Array(array, byteOffset, length)
289 }
290
291 // Return an augmented `Uint8Array` instance
292 Object.setPrototypeOf(buf, Buffer.prototype)
293
294 return buf
295}
296
297function fromObject (obj) {
298 if (Buffer.isBuffer(obj)) {

Callers 2

fromFunction · 0.85
fromArrayViewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…