(string, encoding)
| 2846 | } |
| 2847 | |
| 2848 | function fromString (string, encoding) { |
| 2849 | if (typeof encoding !== 'string' || encoding === '') { |
| 2850 | encoding = 'utf8' |
| 2851 | } |
| 2852 | |
| 2853 | if (!Buffer.isEncoding(encoding)) { |
| 2854 | throw new TypeError('Unknown encoding: ' + encoding) |
| 2855 | } |
| 2856 | |
| 2857 | var length = byteLength(string, encoding) | 0 |
| 2858 | var buf = createBuffer(length) |
| 2859 | |
| 2860 | var actual = buf.write(string, encoding) |
| 2861 | |
| 2862 | if (actual !== length) { |
| 2863 | // Writing a hex string, for example, that contains invalid characters will |
| 2864 | // cause everything after the first invalid character to be ignored. (e.g. |
| 2865 | // 'abxxcd' will be treated as 'ab') |
| 2866 | buf = buf.slice(0, actual) |
| 2867 | } |
| 2868 | |
| 2869 | return buf |
| 2870 | } |
| 2871 | |
| 2872 | function fromArrayLike (array) { |
| 2873 | var length = array.length < 0 ? 0 : checked(array.length) | 0 |
no test coverage detected
searching dependent graphs…