(string, encoding)
| 324 | } |
| 325 | |
| 326 | function fromString (string, encoding) { |
| 327 | if (typeof encoding !== 'string' || encoding === '') { |
| 328 | encoding = 'utf8' |
| 329 | } |
| 330 | |
| 331 | if (!Buffer.isEncoding(encoding)) { |
| 332 | throw new TypeError('Unknown encoding: ' + encoding) |
| 333 | } |
| 334 | |
| 335 | var length = byteLength(string, encoding) | 0 |
| 336 | var buf = createBuffer(length) |
| 337 | |
| 338 | var actual = buf.write(string, encoding) |
| 339 | |
| 340 | if (actual !== length) { |
| 341 | // Writing a hex string, for example, that contains invalid characters will |
| 342 | // cause everything after the first invalid character to be ignored. (e.g. |
| 343 | // 'abxxcd' will be treated as 'ab') |
| 344 | buf = buf.slice(0, actual) |
| 345 | } |
| 346 | |
| 347 | return buf |
| 348 | } |
| 349 | |
| 350 | function fromArrayLike (array) { |
| 351 | var length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected
searching dependent graphs…