(that, string, encoding)
| 78589 | } |
| 78590 | |
| 78591 | function fromString (that, string, encoding) { |
| 78592 | if (typeof encoding !== 'string' || encoding === '') { |
| 78593 | encoding = 'utf8' |
| 78594 | } |
| 78595 | |
| 78596 | if (!Buffer.isEncoding(encoding)) { |
| 78597 | throw new TypeError('"encoding" must be a valid string encoding') |
| 78598 | } |
| 78599 | |
| 78600 | var length = byteLength(string, encoding) | 0 |
| 78601 | that = createBuffer(that, length) |
| 78602 | |
| 78603 | var actual = that.write(string, encoding) |
| 78604 | |
| 78605 | if (actual !== length) { |
| 78606 | // Writing a hex string, for example, that contains invalid characters will |
| 78607 | // cause everything after the first invalid character to be ignored. (e.g. |
| 78608 | // 'abxxcd' will be treated as 'ab') |
| 78609 | that = that.slice(0, actual) |
| 78610 | } |
| 78611 | |
| 78612 | return that |
| 78613 | } |
| 78614 | |
| 78615 | function fromArrayLike (that, array) { |
| 78616 | var length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected