We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 298ff4f commit 1a9f3f9Copy full SHA for 1a9f3f9
lib/buffer.js
@@ -771,13 +771,20 @@ function byteLength(string, encoding) {
771
if (len === 0)
772
return 0;
773
774
- if (encoding) {
775
- const ops = getEncodingOps(encoding);
776
- if (ops) {
777
- return ops.byteLength(string);
778
- }
+ if (!encoding || encoding === 'utf8') {
+ return byteLengthUtf8(string);
+ }
+
+ if (encoding === 'ascii') {
779
+ return len;
780
781
782
+ const ops = getEncodingOps(encoding);
783
+ if (ops === undefined) {
784
+ throw new ERR_UNKNOWN_ENCODING(encoding);
785
}
- return byteLengthUtf8(string);
786
787
+ return ops.byteLength(string);
788
789
790
Buffer.byteLength = byteLength;
0 commit comments