(that, obj)
| 876 | } |
| 877 | |
| 878 | function fromObject (that, obj) { |
| 879 | if (Buffer.isBuffer(obj)) { |
| 880 | var len = checked(obj.length) | 0 |
| 881 | that = createBuffer(that, len) |
| 882 | |
| 883 | if (that.length === 0) { |
| 884 | return that |
| 885 | } |
| 886 | |
| 887 | obj.copy(that, 0, 0, len) |
| 888 | return that |
| 889 | } |
| 890 | |
| 891 | if (obj) { |
| 892 | if ((typeof ArrayBuffer !== 'undefined' && |
| 893 | obj.buffer instanceof ArrayBuffer) || 'length' in obj) { |
| 894 | if (typeof obj.length !== 'number' || isnan(obj.length)) { |
| 895 | return createBuffer(that, 0) |
| 896 | } |
| 897 | return fromArrayLike(that, obj) |
| 898 | } |
| 899 | |
| 900 | if (obj.type === 'Buffer' && isArray(obj.data)) { |
| 901 | return fromArrayLike(that, obj.data) |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') |
| 906 | } |
| 907 | |
| 908 | function checked (length) { |
| 909 | // Note: cannot use `length < kMaxLength()` here because that fails when |
no test coverage detected