ac30738327faa63ec7c194acf2232befdef62baf
[platform/framework/web/wrtjs.git] / device_home / node_modules / buffer-fill / readme.md
1 # Buffer Fill
2
3 A [ponyfill](https://ponyfill.com) for `Buffer.fill`.
4
5 Works as Node.js: `v6.4.0` <br>
6 Works on Node.js: `v0.10.0`
7
8 ## Installation
9
10 ```sh
11 npm install --save buffer-fill
12 ```
13
14 ## Usage
15
16 ```js
17 const fill = require('buffer-fill')
18 const buf = Buffer.allocUnsafe(5)
19
20 console.log(buf.fill(8))
21 //=> <Buffer 08 08 08 08 08>
22
23 console.log(buf.fill(9, 2, 4))
24 //=> <Buffer 08 08 09 09 08>
25
26 console.log(buf.fill('linus', 'latin1'))
27 //=> <Buffer 6c 69 6e 75 73>
28
29 console.log(buf.fill('\u0222'))
30 //=> <Buffer c8 a2 c8 a2 c8>
31 ```
32
33 ## API
34
35 ### fill(buf, value[, offset[, end]][, encoding])
36
37 - `value` &lt;String&gt; | &lt;Buffer&gt; | &lt;Integer&gt; The value to fill `buf` with
38 - `offset` &lt;Integer&gt; Where to start filling `buf`. **Default:** `0`
39 - `end` &lt;Integer&gt; Where to stop filling `buf` (not inclusive). **Default:** `buf.length`
40 - `encoding` &lt;String&gt; If `value` is a string, this is its encoding. **Default:** `'utf8'`
41 - Return: &lt;Buffer&gt; A reference to `buf`
42
43 Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
44 the entire `buf` will be filled. This is meant to be a small simplification to
45 allow the creation and filling of a `Buffer` to be done on a single line.
46
47 If the final write of a `fill()` operation falls on a multi-byte character, then
48 only the first bytes of that character that fit into `buf` are written.
49
50 ## See also
51
52 - [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
53 - [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
54 - [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`