| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -780,13 +780,22 @@ function byteLength(string, encoding) { | |||
| 780 | 780 | if (len === 0) | |
| 781 | 781 | return 0; | |
| 782 | 782 | ||
| 783 | - if (encoding) { | ||
| 784 | - const ops = getEncodingOps(encoding); | ||
| 785 | - if (ops) { | ||
| 786 | - return ops.byteLength(string); | ||
| 787 | - } | ||
| 783 | + if (!encoding || encoding === 'utf8') { | ||
| 784 | + return byteLengthUtf8(string); | ||
| 785 | + } | ||
| 786 | + | ||
| 787 | + if (encoding === 'ascii') { | ||
| 788 | + return len; | ||
| 788 | 789 | } | |
| 789 | - return byteLengthUtf8(string); | ||
| 790 | + | ||
| 791 | + const ops = getEncodingOps(encoding); | ||
| 792 | + if (ops === undefined) { | ||
| 793 | + // TODO (ronag): Makes more sense to throw here. | ||
| 794 | + // throw new ERR_UNKNOWN_ENCODING(encoding); | ||
| 795 | + return byteLengthUtf8(string); | ||
| 796 | + } | ||
| 797 | + | ||
| 798 | + return ops.byteLength(string); | ||
| 790 | 799 | } | |
| 791 | 800 | ||
| 792 | 801 | Buffer.byteLength = byteLength; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments