MCPcopy Create free account
hub / github.com/bitpay/bitcore-message / fromArrayBuffer

Function fromArrayBuffer

bitcore-message.js:544–572  ·  view source on GitHub ↗
(that, array, byteOffset, length)

Source from the content-addressed store, hash-verified

542}
543
544function fromArrayBuffer (that, array, byteOffset, length) {
545 array.byteLength // this throws if `array` is not a valid ArrayBuffer
546
547 if (byteOffset < 0 || array.byteLength < byteOffset) {
548 throw new RangeError('\'offset\' is out of bounds')
549 }
550
551 if (array.byteLength < byteOffset + (length || 0)) {
552 throw new RangeError('\'length\' is out of bounds')
553 }
554
555 if (byteOffset === undefined && length === undefined) {
556 array = new Uint8Array(array)
557 } else if (length === undefined) {
558 array = new Uint8Array(array, byteOffset)
559 } else {
560 array = new Uint8Array(array, byteOffset, length)
561 }
562
563 if (Buffer.TYPED_ARRAY_SUPPORT) {
564 // Return an augmented `Uint8Array` instance, for best performance
565 that = array
566 that.__proto__ = Buffer.prototype
567 } else {
568 // Fallback: Return an object instance of the Buffer class
569 that = fromArrayLike(that, array)
570 }
571 return that
572}
573
574function fromObject (that, obj) {
575 if (Buffer.isBuffer(obj)) {

Callers 1

fromFunction · 0.85

Calls 1

fromArrayLikeFunction · 0.85

Tested by

no test coverage detected