File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Open diff view settings
Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ Creates a new `StringDecoder` instance.
5959added: v0.9.3
6060-->
6161
62- * ` buffer ` {Buffer} A ` Buffer ` containing the bytes to decode.
62+ * ` buffer ` {Buffer|TypedArray|DataView} A ` Buffer ` , or ` TypedArray ` , or
63+ ` DataView ` containing the bytes to decode.
6364* Returns: {string}
6465
6566Returns any remaining input stored in the internal buffer as a string. Bytes
@@ -79,10 +80,11 @@ changes:
7980 character instead of one for each individual byte.
8081-->
8182
82- * ` buffer ` {Buffer} A ` Buffer ` containing the bytes to decode.
83+ * ` buffer ` {Buffer|TypedArray|DataView} A ` Buffer ` , or ` TypedArray ` , or
84+ ` DataView ` containing the bytes to decode.
8385* Returns: {string}
8486
8587Returns a decoded string, ensuring that any incomplete multibyte characters at
86- the end of the ` Buffer ` are omitted from the returned string and stored in an
87- internal buffer for the next call to ` stringDecoder.write() ` or
88- ` stringDecoder.end() ` .
88+ the end of the ` Buffer ` , or ` TypedArray ` , or ` DataView ` are omitted from the
89+ returned string and stored in an internal buffer for the next call to
90+ ` stringDecoder.write() ` or ` stringDecoder.end() ` .
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ StringDecoder.prototype.write = function write(buf) {
7373 return buf ;
7474 if ( ! ArrayBuffer . isView ( buf ) )
7575 throw new ERR_INVALID_ARG_TYPE ( 'buf' ,
76- [ 'Buffer' , 'Uint8Array ' , 'ArrayBufferView ' ] ,
76+ [ 'Buffer' , 'TypedArray ' , 'DataView ' ] ,
7777 buf ) ;
7878 return decode ( this [ kNativeDecoder ] , buf ) ;
7979} ;
Original file line number Diff line number Diff line change @@ -97,6 +97,17 @@ assert.strictEqual(decoder.lastTotal, 3);
9797
9898assert . strictEqual ( decoder . end ( ) , '\ufffd' ) ;
9999
100+ // ArrayBufferView tests
101+ const arrayBufferViewStr = 'String for ArrayBufferView tests\n' ;
102+ const inputBuffer = Buffer . from ( arrayBufferViewStr . repeat ( 8 ) , 'utf8' ) ;
103+ for ( const expectView of common . getArrayBufferViews ( inputBuffer ) ) {
104+ assert . strictEqual (
105+ decoder . write ( expectView ) ,
106+ inputBuffer . toString ( 'utf8' )
107+ ) ;
108+ assert . strictEqual ( decoder . end ( ) , '' ) ;
109+ }
110+
100111decoder = new StringDecoder ( 'utf8' ) ;
101112assert . strictEqual ( decoder . write ( Buffer . from ( 'E18B' , 'hex' ) ) , '' ) ;
102113assert . strictEqual ( decoder . end ( ) , '\ufffd' ) ;
@@ -174,8 +185,8 @@ common.expectsError(
174185 {
175186 code : 'ERR_INVALID_ARG_TYPE' ,
176187 type : TypeError ,
177- message : 'The "buf" argument must be one of type Buffer, Uint8Array, or ' +
178- ' ArrayBufferView . Received type object'
188+ message : 'The "buf" argument must be one of type Buffer, TypedArray, ' +
189+ ' or DataView . Received type object'
179190 }
180191) ;
181192
You can’t perform that action at this time.
0 commit comments