(obj)
| 295 | } |
| 296 | |
| 297 | function fromObject (obj) { |
| 298 | if (Buffer.isBuffer(obj)) { |
| 299 | const len = checked(obj.length) | 0 |
| 300 | const buf = createBuffer(len) |
| 301 | |
| 302 | if (buf.length === 0) { |
| 303 | return buf |
| 304 | } |
| 305 | |
| 306 | obj.copy(buf, 0, 0, len) |
| 307 | return buf |
| 308 | } |
| 309 | |
| 310 | if (obj.length !== undefined) { |
| 311 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { |
| 312 | return createBuffer(0) |
| 313 | } |
| 314 | return fromArrayLike(obj) |
| 315 | } |
| 316 | |
| 317 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { |
| 318 | return fromArrayLike(obj.data) |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | function checked (length) { |
| 323 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when |
no test coverage detected
searching dependent graphs…