(obj)
| 2902 | } |
| 2903 | |
| 2904 | function fromObject (obj) { |
| 2905 | if (Buffer.isBuffer(obj)) { |
| 2906 | var len = checked(obj.length) | 0 |
| 2907 | var buf = createBuffer(len) |
| 2908 | |
| 2909 | if (buf.length === 0) { |
| 2910 | return buf |
| 2911 | } |
| 2912 | |
| 2913 | obj.copy(buf, 0, 0, len) |
| 2914 | return buf |
| 2915 | } |
| 2916 | |
| 2917 | if (obj.length !== undefined) { |
| 2918 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { |
| 2919 | return createBuffer(0) |
| 2920 | } |
| 2921 | return fromArrayLike(obj) |
| 2922 | } |
| 2923 | |
| 2924 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { |
| 2925 | return fromArrayLike(obj.data) |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | function checked (length) { |
| 2930 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when |
no test coverage detected
searching dependent graphs…