(that, obj)
| 9972 | } |
| 9973 | |
| 9974 | function fromObject (that, obj) { |
| 9975 | if (Buffer.isBuffer(obj)) { |
| 9976 | var len = checked(obj.length) | 0 |
| 9977 | that = createBuffer(that, len) |
| 9978 | |
| 9979 | if (that.length === 0) { |
| 9980 | return that |
| 9981 | } |
| 9982 | |
| 9983 | obj.copy(that, 0, 0, len) |
| 9984 | return that |
| 9985 | } |
| 9986 | |
| 9987 | if (obj) { |
| 9988 | if ((typeof ArrayBuffer !== 'undefined' && |
| 9989 | obj.buffer instanceof ArrayBuffer) || 'length' in obj) { |
| 9990 | if (typeof obj.length !== 'number' || isnan(obj.length)) { |
| 9991 | return createBuffer(that, 0) |
| 9992 | } |
| 9993 | return fromArrayLike(that, obj) |
| 9994 | } |
| 9995 | |
| 9996 | if (obj.type === 'Buffer' && isArray(obj.data)) { |
| 9997 | return fromArrayLike(that, obj.data) |
| 9998 | } |
| 9999 | } |
| 10000 | |
| 10001 | throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') |
| 10002 | } |
| 10003 | |
| 10004 | function checked (length) { |
| 10005 | // Note: cannot use `length < kMaxLength()` here because that fails when |
no test coverage detected