GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: buffer.fill empty value · nodejs/node@108220c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • buffer.md
  • test/parallel
    • test-buffer-fill.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/buffer.md‎

Copy file name to clipboardExpand all lines: doc/api/buffer.md
+13Lines changed: 13 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff 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

19031904
console.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

19141921
console.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
Collapse file

‎test/parallel/test-buffer-fill.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-fill.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.