| 9942 | } |
| 9943 | |
| 9944 | function fromArrayBuffer (that, array, byteOffset, length) { |
| 9945 | array.byteLength // this throws if `array` is not a valid ArrayBuffer |
| 9946 | |
| 9947 | if (byteOffset < 0 || array.byteLength < byteOffset) { |
| 9948 | throw new RangeError('\'offset\' is out of bounds') |
| 9949 | } |
| 9950 | |
| 9951 | if (array.byteLength < byteOffset + (length || 0)) { |
| 9952 | throw new RangeError('\'length\' is out of bounds') |
| 9953 | } |
| 9954 | |
| 9955 | if (byteOffset === undefined && length === undefined) { |
| 9956 | array = new Uint8Array(array) |
| 9957 | } else if (length === undefined) { |
| 9958 | array = new Uint8Array(array, byteOffset) |
| 9959 | } else { |
| 9960 | array = new Uint8Array(array, byteOffset, length) |
| 9961 | } |
| 9962 | |
| 9963 | if (Buffer.TYPED_ARRAY_SUPPORT) { |
| 9964 | // Return an augmented `Uint8Array` instance, for best performance |
| 9965 | that = array |
| 9966 | that.__proto__ = Buffer.prototype |
| 9967 | } else { |
| 9968 | // Fallback: Return an object instance of the Buffer class |
| 9969 | that = fromArrayLike(that, array) |
| 9970 | } |
| 9971 | return that |
| 9972 | } |
| 9973 | |
| 9974 | function fromObject (that, obj) { |
| 9975 | if (Buffer.isBuffer(obj)) { |