(string, encoding)
| 384 | return buffer; |
| 385 | }; |
| 386 | function byteLength(string, encoding) { |
| 387 | if (Buffer.isBuffer(string)) { |
| 388 | return string.length; |
| 389 | } |
| 390 | if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { |
| 391 | return string.byteLength; |
| 392 | } |
| 393 | if (typeof string !== 'string') { |
| 394 | throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string)); |
| 395 | } |
| 396 | var len = string.length; |
| 397 | var mustMatch = arguments.length > 2 && arguments[2] === true; |
| 398 | if (!mustMatch && len === 0) return 0; |
| 399 | |
| 400 | // Use a for loop to avoid recursion |
| 401 | var loweredCase = false; |
| 402 | for (;;) { |
| 403 | switch (encoding) { |
| 404 | case 'ascii': |
| 405 | case 'latin1': |
| 406 | case 'binary': |
| 407 | return len; |
| 408 | case 'utf8': |
| 409 | case 'utf-8': |
| 410 | return utf8ToBytes(string).length; |
| 411 | case 'ucs2': |
| 412 | case 'ucs-2': |
| 413 | case 'utf16le': |
| 414 | case 'utf-16le': |
| 415 | return len * 2; |
| 416 | case 'hex': |
| 417 | return len >>> 1; |
| 418 | case 'base64': |
| 419 | return base64ToBytes(string).length; |
| 420 | default: |
| 421 | if (loweredCase) { |
| 422 | return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 |
| 423 | } |
| 424 | encoding = ('' + encoding).toLowerCase(); |
| 425 | loweredCase = true; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | Buffer.byteLength = byteLength; |
| 430 | function slowToString(encoding, start, end) { |
| 431 | var loweredCase = false; |
no test coverage detected
searching dependent graphs…