(obj)
| 275 | return buf; |
| 276 | } |
| 277 | function fromObject(obj) { |
| 278 | if (Buffer.isBuffer(obj)) { |
| 279 | var len = checked(obj.length) | 0; |
| 280 | var buf = createBuffer(len); |
| 281 | if (buf.length === 0) { |
| 282 | return buf; |
| 283 | } |
| 284 | obj.copy(buf, 0, 0, len); |
| 285 | return buf; |
| 286 | } |
| 287 | if (obj.length !== undefined) { |
| 288 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { |
| 289 | return createBuffer(0); |
| 290 | } |
| 291 | return fromArrayLike(obj); |
| 292 | } |
| 293 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { |
| 294 | return fromArrayLike(obj.data); |
| 295 | } |
| 296 | } |
| 297 | function checked(length) { |
| 298 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when |
| 299 | // length is NaN (which is otherwise coerced to zero.) |
no test coverage detected
searching dependent graphs…