(string, encoding)
| 222 | return allocUnsafe(size); |
| 223 | }; |
| 224 | function fromString(string, encoding) { |
| 225 | if (typeof encoding !== 'string' || encoding === '') { |
| 226 | encoding = 'utf8'; |
| 227 | } |
| 228 | if (!Buffer.isEncoding(encoding)) { |
| 229 | throw new TypeError('Unknown encoding: ' + encoding); |
| 230 | } |
| 231 | var length = byteLength(string, encoding) | 0; |
| 232 | var buf = createBuffer(length); |
| 233 | var actual = buf.write(string, encoding); |
| 234 | if (actual !== length) { |
| 235 | // Writing a hex string, for example, that contains invalid characters will |
| 236 | // cause everything after the first invalid character to be ignored. (e.g. |
| 237 | // 'abxxcd' will be treated as 'ab') |
| 238 | buf = buf.slice(0, actual); |
| 239 | } |
| 240 | return buf; |
| 241 | } |
| 242 | function fromArrayLike(array) { |
| 243 | var length = array.length < 0 ? 0 : checked(array.length) | 0; |
| 244 | var buf = createBuffer(length); |
no test coverage detected
searching dependent graphs…