| 8905 | } |
| 8906 | |
| 8907 | function fromArrayBuffer (that, array, byteOffset, length) { |
| 8908 | array.byteLength; // this throws if `array` is not a valid ArrayBuffer |
| 8909 | |
| 8910 | if (byteOffset < 0 || array.byteLength < byteOffset) { |
| 8911 | throw new RangeError('\'offset\' is out of bounds') |
| 8912 | } |
| 8913 | |
| 8914 | if (array.byteLength < byteOffset + (length || 0)) { |
| 8915 | throw new RangeError('\'length\' is out of bounds') |
| 8916 | } |
| 8917 | |
| 8918 | if (byteOffset === undefined && length === undefined) { |
| 8919 | array = new Uint8Array(array); |
| 8920 | } else if (length === undefined) { |
| 8921 | array = new Uint8Array(array, byteOffset); |
| 8922 | } else { |
| 8923 | array = new Uint8Array(array, byteOffset, length); |
| 8924 | } |
| 8925 | |
| 8926 | if (Buffer.TYPED_ARRAY_SUPPORT) { |
| 8927 | // Return an augmented `Uint8Array` instance, for best performance |
| 8928 | that = array; |
| 8929 | that.__proto__ = Buffer.prototype; |
| 8930 | } else { |
| 8931 | // Fallback: Return an object instance of the Buffer class |
| 8932 | that = fromArrayLike(that, array); |
| 8933 | } |
| 8934 | return that |
| 8935 | } |
| 8936 | |
| 8937 | function fromObject (that, obj) { |
| 8938 | if (internalIsBuffer(obj)) { |