File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1884,6 +1884,7 @@ changes:
1884
1884
-->
1885
1885
1886
1886
* ` value ` {string|Buffer|Uint8Array|integer} The value with which to fill ` buf ` .
1887
+ Empty value (string, Uint8Array, Buffer) is coerced to ` 0 ` .
1887
1888
* ` offset ` {integer} Number of bytes to skip before starting to fill ` buf ` .
1888
1889
** Default:** ` 0 ` .
1889
1890
* ` end ` {integer} Where to stop filling ` buf ` (not inclusive). ** Default:**
@@ -1904,6 +1905,12 @@ const b = Buffer.allocUnsafe(50).fill('h');
1904
1905
1905
1906
console .log (b .toString ());
1906
1907
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
1908
+
1909
+ // Fill a buffer with empty string
1910
+ const c = Buffer .allocUnsafe (5 ).fill (' ' );
1911
+
1912
+ console .log (c .fill (' ' ));
1913
+ // Prints: <Buffer 00 00 00 00 00>
1907
1914
```
1908
1915
1909
1916
``` cjs
@@ -1915,6 +1922,12 @@ const b = Buffer.allocUnsafe(50).fill('h');
1915
1922
1916
1923
console .log (b .toString ());
1917
1924
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
1925
+
1926
+ // Fill a buffer with empty string
1927
+ const c = Buffer .allocUnsafe (5 ).fill (' ' );
1928
+
1929
+ console .log (c .fill (' ' ));
1930
+ // Prints: <Buffer 00 00 00 00 00>
1918
1931
```
1919
1932
1920
1933
` 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(() => {
429
429
code : 'ERR_INVALID_ARG_VALUE' ,
430
430
name : 'TypeError'
431
431
} ) ;
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