doc: buffer.fill empty value
PR-URL: https://github.com/nodejs/node/pull/45794 Fixes: https://github.com/nodejs/node/issues/45727 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
This commit is contained in:
parent
2483da743c
commit
c6c3eea470
@ -1884,6 +1884,7 @@ changes:
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
* `value` {string|Buffer|Uint8Array|integer} The value with which to fill `buf`.
|
* `value` {string|Buffer|Uint8Array|integer} The value with which to fill `buf`.
|
||||||
|
Empty value (string, Uint8Array, Buffer) is coerced to `0`.
|
||||||
* `offset` {integer} Number of bytes to skip before starting to fill `buf`.
|
* `offset` {integer} Number of bytes to skip before starting to fill `buf`.
|
||||||
**Default:** `0`.
|
**Default:** `0`.
|
||||||
* `end` {integer} Where to stop filling `buf` (not inclusive). **Default:**
|
* `end` {integer} Where to stop filling `buf` (not inclusive). **Default:**
|
||||||
@ -1904,6 +1905,12 @@ const b = Buffer.allocUnsafe(50).fill('h');
|
|||||||
|
|
||||||
console.log(b.toString());
|
console.log(b.toString());
|
||||||
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
|
|
||||||
|
// Fill a buffer with empty string
|
||||||
|
const c = Buffer.allocUnsafe(5).fill('');
|
||||||
|
|
||||||
|
console.log(c.fill(''));
|
||||||
|
// Prints: <Buffer 00 00 00 00 00>
|
||||||
```
|
```
|
||||||
|
|
||||||
```cjs
|
```cjs
|
||||||
@ -1915,6 +1922,12 @@ const b = Buffer.allocUnsafe(50).fill('h');
|
|||||||
|
|
||||||
console.log(b.toString());
|
console.log(b.toString());
|
||||||
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
|
|
||||||
|
// Fill a buffer with empty string
|
||||||
|
const c = Buffer.allocUnsafe(5).fill('');
|
||||||
|
|
||||||
|
console.log(c.fill(''));
|
||||||
|
// Prints: <Buffer 00 00 00 00 00>
|
||||||
```
|
```
|
||||||
|
|
||||||
`value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
|
`value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
|
||||||
|
@ -429,3 +429,18 @@ assert.throws(() => {
|
|||||||
code: 'ERR_INVALID_ARG_VALUE',
|
code: 'ERR_INVALID_ARG_VALUE',
|
||||||
name: 'TypeError'
|
name: 'TypeError'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
const bufEmptyString = Buffer.alloc(5, '');
|
||||||
|
assert.strictEqual(bufEmptyString.toString(), '\x00\x00\x00\x00\x00');
|
||||||
|
|
||||||
|
const bufEmptyArray = Buffer.alloc(5, []);
|
||||||
|
assert.strictEqual(bufEmptyArray.toString(), '\x00\x00\x00\x00\x00');
|
||||||
|
|
||||||
|
const bufEmptyBuffer = Buffer.alloc(5, Buffer.alloc(5));
|
||||||
|
assert.strictEqual(bufEmptyBuffer.toString(), '\x00\x00\x00\x00\x00');
|
||||||
|
|
||||||
|
const bufZero = Buffer.alloc(5, 0);
|
||||||
|
assert.strictEqual(bufZero.toString(), '\x00\x00\x00\x00\x00');
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user