File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -782,13 +782,22 @@ function byteLength(string, encoding) {
782
782
if ( len === 0 )
783
783
return 0 ;
784
784
785
- if ( encoding ) {
786
- const ops = getEncodingOps ( encoding ) ;
787
- if ( ops ) {
788
- return ops . byteLength ( string ) ;
789
- }
785
+ if ( ! encoding || encoding === 'utf8' ) {
786
+ return byteLengthUtf8 ( string ) ;
787
+ }
788
+
789
+ if ( encoding === 'ascii' ) {
790
+ return len ;
790
791
}
791
- return byteLengthUtf8 ( string ) ;
792
+
793
+ const ops = getEncodingOps ( encoding ) ;
794
+ if ( ops === undefined ) {
795
+ // TODO (ronag): Makes more sense to throw here.
796
+ // throw new ERR_UNKNOWN_ENCODING(encoding);
797
+ return byteLengthUtf8 ( string ) ;
798
+ }
799
+
800
+ return ops . byteLength ( string ) ;
792
801
}
793
802
794
803
Buffer . byteLength = byteLength ;
You can’t perform that action at this time.
0 commit comments