(that, string, encoding)
| 2082 | }; |
| 2083 | |
| 2084 | function fromString (that, string, encoding) { |
| 2085 | if (typeof encoding !== 'string' || encoding === '') { |
| 2086 | encoding = 'utf8'; |
| 2087 | } |
| 2088 | |
| 2089 | if (!Buffer.isEncoding(encoding)) { |
| 2090 | throw new TypeError('"encoding" must be a valid string encoding') |
| 2091 | } |
| 2092 | |
| 2093 | var length = byteLength(string, encoding) | 0; |
| 2094 | that = createBuffer(that, length); |
| 2095 | |
| 2096 | var actual = that.write(string, encoding); |
| 2097 | |
| 2098 | if (actual !== length) { |
| 2099 | // Writing a hex string, for example, that contains invalid characters will |
| 2100 | // cause everything after the first invalid character to be ignored. (e.g. |
| 2101 | // 'abxxcd' will be treated as 'ab') |
| 2102 | that = that.slice(0, actual); |
| 2103 | } |
| 2104 | |
| 2105 | return that |
| 2106 | } |
| 2107 | |
| 2108 | function fromArrayLike (that, array) { |
| 2109 | var length = array.length < 0 ? 0 : checked(array.length) | 0; |
no test coverage detected