File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1882,6 +1882,7 @@ changes:
18821882-->
18831883
18841884* ` value ` {string|Buffer|Uint8Array|integer} The value with which to fill ` buf ` .
1885+ Empty value (string, Uint8Array, Buffer) is coerced to ` 0 ` .
18851886* ` offset ` {integer} Number of bytes to skip before starting to fill ` buf ` .
18861887 ** Default:** ` 0 ` .
18871888* ` end ` {integer} Where to stop filling ` buf ` (not inclusive). ** Default:**
@@ -1902,6 +1903,12 @@ const b = Buffer.allocUnsafe(50).fill('h');
19021903
19031904console .log (b .toString ());
19041905// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
1906+
1907+ // Fill a buffer with empty string
1908+ const c = Buffer .allocUnsafe (5 ).fill (' ' );
1909+
1910+ console .log (c .fill (' ' ));
1911+ // Prints: <Buffer 00 00 00 00 00>
19051912```
19061913
19071914``` cjs
@@ -1913,6 +1920,12 @@ const b = Buffer.allocUnsafe(50).fill('h');
19131920
19141921console .log (b .toString ());
19151922// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
1923+
1924+ // Fill a buffer with empty string
1925+ const c = Buffer .allocUnsafe (5 ).fill (' ' );
1926+
1927+ console .log (c .fill (' ' ));
1928+ // Prints: <Buffer 00 00 00 00 00>
19161929```
19171930
19181931` value ` is coerced to a ` uint32 ` value if it is not a string, ` Buffer ` , or
Original file line number Diff line number Diff line change @@ -429,3 +429,18 @@ assert.throws(() => {
429429 code : 'ERR_INVALID_ARG_VALUE' ,
430430 name : 'TypeError'
431431} ) ;
432+
433+
434+ {
435+ const bufEmptyString = Buffer . alloc ( 5 , '' ) ;
436+ assert . strictEqual ( bufEmptyString . toString ( ) , '\x00\x00\x00\x00\x00' ) ;
437+
438+ const bufEmptyArray = Buffer . alloc ( 5 , [ ] ) ;
439+ assert . strictEqual ( bufEmptyArray . toString ( ) , '\x00\x00\x00\x00\x00' ) ;
440+
441+ const bufEmptyBuffer = Buffer . alloc ( 5 , Buffer . alloc ( 5 ) ) ;
442+ assert . strictEqual ( bufEmptyBuffer . toString ( ) , '\x00\x00\x00\x00\x00' ) ;
443+
444+ const bufZero = Buffer . alloc ( 5 , 0 ) ;
445+ assert . strictEqual ( bufZero . toString ( ) , '\x00\x00\x00\x00\x00' ) ;
446+ }
You can’t perform that action at this time.
0 commit comments