(obj)
| 380 | } |
| 381 | |
| 382 | function fromObject (obj) { |
| 383 | if (Buffer.isBuffer(obj)) { |
| 384 | var len = checked(obj.length) | 0 |
| 385 | var buf = createBuffer(len) |
| 386 | |
| 387 | if (buf.length === 0) { |
| 388 | return buf |
| 389 | } |
| 390 | |
| 391 | obj.copy(buf, 0, 0, len) |
| 392 | return buf |
| 393 | } |
| 394 | |
| 395 | if (obj) { |
| 396 | if (ArrayBuffer.isView(obj) || 'length' in obj) { |
| 397 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { |
| 398 | return createBuffer(0) |
| 399 | } |
| 400 | return fromArrayLike(obj) |
| 401 | } |
| 402 | |
| 403 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { |
| 404 | return fromArrayLike(obj.data) |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.') |
| 409 | } |
| 410 | |
| 411 | function checked (length) { |
| 412 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when |
no test coverage detected
searching dependent graphs…