(string, encoding)
| 230 | } |
| 231 | |
| 232 | function fromString (string, encoding) { |
| 233 | if (typeof encoding !== 'string' || encoding === '') { |
| 234 | encoding = 'utf8' |
| 235 | } |
| 236 | |
| 237 | if (!Buffer.isEncoding(encoding)) { |
| 238 | throw new TypeError('Unknown encoding: ' + encoding) |
| 239 | } |
| 240 | |
| 241 | const length = byteLength(string, encoding) | 0 |
| 242 | let buf = createBuffer(length) |
| 243 | |
| 244 | const actual = buf.write(string, encoding) |
| 245 | |
| 246 | if (actual !== length) { |
| 247 | // Writing a hex string, for example, that contains invalid characters will |
| 248 | // cause everything after the first invalid character to be ignored. (e.g. |
| 249 | // 'abxxcd' will be treated as 'ab') |
| 250 | buf = buf.slice(0, actual) |
| 251 | } |
| 252 | |
| 253 | return buf |
| 254 | } |
| 255 | |
| 256 | function fromArrayLike (array) { |
| 257 | const length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected
searching dependent graphs…