(that, string, encoding)
| 813 | } |
| 814 | |
| 815 | function fromString (that, string, encoding) { |
| 816 | if (typeof encoding !== 'string' || encoding === '') { |
| 817 | encoding = 'utf8' |
| 818 | } |
| 819 | |
| 820 | if (!Buffer.isEncoding(encoding)) { |
| 821 | throw new TypeError('"encoding" must be a valid string encoding') |
| 822 | } |
| 823 | |
| 824 | var length = byteLength(string, encoding) | 0 |
| 825 | that = createBuffer(that, length) |
| 826 | |
| 827 | var actual = that.write(string, encoding) |
| 828 | |
| 829 | if (actual !== length) { |
| 830 | // Writing a hex string, for example, that contains invalid characters will |
| 831 | // cause everything after the first invalid character to be ignored. (e.g. |
| 832 | // 'abxxcd' will be treated as 'ab') |
| 833 | that = that.slice(0, actual) |
| 834 | } |
| 835 | |
| 836 | return that |
| 837 | } |
| 838 | |
| 839 | function fromArrayLike (that, array) { |
| 840 | var length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected