(that, string, encoding)
| 509 | } |
| 510 | |
| 511 | function fromString (that, string, encoding) { |
| 512 | if (typeof encoding !== 'string' || encoding === '') { |
| 513 | encoding = 'utf8' |
| 514 | } |
| 515 | |
| 516 | if (!Buffer.isEncoding(encoding)) { |
| 517 | throw new TypeError('"encoding" must be a valid string encoding') |
| 518 | } |
| 519 | |
| 520 | var length = byteLength(string, encoding) | 0 |
| 521 | that = createBuffer(that, length) |
| 522 | |
| 523 | var actual = that.write(string, encoding) |
| 524 | |
| 525 | if (actual !== length) { |
| 526 | // Writing a hex string, for example, that contains invalid characters will |
| 527 | // cause everything after the first invalid character to be ignored. (e.g. |
| 528 | // 'abxxcd' will be treated as 'ab') |
| 529 | that = that.slice(0, actual) |
| 530 | } |
| 531 | |
| 532 | return that |
| 533 | } |
| 534 | |
| 535 | function fromArrayLike (that, array) { |
| 536 | var length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected