https://github.com/linusu/buffer-fill
A ponyfill for Buffer.fill
https://github.com/linusu/buffer-fill
Last synced: about 1 year ago
JSON representation
A ponyfill for Buffer.fill
- Host: GitHub
- URL: https://github.com/linusu/buffer-fill
- Owner: LinusU
- License: mit
- Created: 2016-08-19T06:23:07.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-20T13:25:59.000Z (over 7 years ago)
- Last Synced: 2025-04-28T16:12:00.958Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Buffer Fill
A [ponyfill](https://ponyfill.com) for `Buffer.fill`.
Works as Node.js: `v6.4.0`
Works on Node.js: `v0.10.0`
## Installation
```sh
npm install --save buffer-fill
```
## Usage
```js
const fill = require('buffer-fill')
const buf = Buffer.allocUnsafe(5)
console.log(buf.fill(8))
//=>
console.log(buf.fill(9, 2, 4))
//=>
console.log(buf.fill('linus', 'latin1'))
//=>
console.log(buf.fill('\u0222'))
//=>
```
## API
### fill(buf, value[, offset[, end]][, encoding])
- `value` <String> | <Buffer> | <Integer> The value to fill `buf` with
- `offset` <Integer> Where to start filling `buf`. **Default:** `0`
- `end` <Integer> Where to stop filling `buf` (not inclusive). **Default:** `buf.length`
- `encoding` <String> If `value` is a string, this is its encoding. **Default:** `'utf8'`
- Return: <Buffer> A reference to `buf`
Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
the entire `buf` will be filled. This is meant to be a small simplification to
allow the creation and filling of a `Buffer` to be done on a single line.
If the final write of a `fill()` operation falls on a multi-byte character, then
only the first bytes of that character that fit into `buf` are written.
## See also
- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
- [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`