(string, encoding)
| 835 | } |
| 836 | |
| 837 | function byteLength(string, encoding) { |
| 838 | if (typeof string !== 'string') { |
| 839 | if (isArrayBufferView(string) || isAnyArrayBuffer(string)) { |
| 840 | return string.byteLength; |
| 841 | } |
| 842 | |
| 843 | throw new ERR_INVALID_ARG_TYPE( |
| 844 | 'string', ['string', 'Buffer', 'ArrayBuffer'], string, |
| 845 | ); |
| 846 | } |
| 847 | |
| 848 | const len = string.length; |
| 849 | if (len === 0) |
| 850 | return 0; |
| 851 | |
| 852 | if (!encoding || encoding === 'utf8') { |
| 853 | return byteLengthUtf8(string); |
| 854 | } |
| 855 | |
| 856 | if (encoding === 'ascii') { |
| 857 | return len; |
| 858 | } |
| 859 | |
| 860 | const ops = getEncodingOps(encoding); |
| 861 | if (ops === undefined) { |
| 862 | // TODO (ronag): Makes more sense to throw here. |
| 863 | // throw new ERR_UNKNOWN_ENCODING(encoding); |
| 864 | return byteLengthUtf8(string); |
| 865 | } |
| 866 | |
| 867 | return ops.byteLength(string); |
| 868 | } |
| 869 | |
| 870 | Buffer.byteLength = byteLength; |
| 871 |
nothing calls this directly
no test coverage detected
searching dependent graphs…