(that, string, encoding)
| 9909 | } |
| 9910 | |
| 9911 | function fromString (that, string, encoding) { |
| 9912 | if (typeof encoding !== 'string' || encoding === '') { |
| 9913 | encoding = 'utf8' |
| 9914 | } |
| 9915 | |
| 9916 | if (!Buffer.isEncoding(encoding)) { |
| 9917 | throw new TypeError('"encoding" must be a valid string encoding') |
| 9918 | } |
| 9919 | |
| 9920 | var length = byteLength(string, encoding) | 0 |
| 9921 | that = createBuffer(that, length) |
| 9922 | |
| 9923 | var actual = that.write(string, encoding) |
| 9924 | |
| 9925 | if (actual !== length) { |
| 9926 | // Writing a hex string, for example, that contains invalid characters will |
| 9927 | // cause everything after the first invalid character to be ignored. (e.g. |
| 9928 | // 'abxxcd' will be treated as 'ab') |
| 9929 | that = that.slice(0, actual) |
| 9930 | } |
| 9931 | |
| 9932 | return that |
| 9933 | } |
| 9934 | |
| 9935 | function fromArrayLike (that, array) { |
| 9936 | var length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected