80c7d7bb8d85bf9a82e7cae49ab6b067eaa00167
[platform/framework/web/wrtjs.git] / device_home / node_modules / buffer-alloc / readme.md
1 # Buffer Alloc
2
3 A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.
4
5 Works as Node.js: `v7.0.0` <br>
6 Works on Node.js: `v0.10.0`
7
8 ## Installation
9
10 ```sh
11 npm install --save buffer-alloc
12 ```
13
14 ## Usage
15
16 ```js
17 const alloc = require('buffer-alloc')
18
19 console.log(alloc(4))
20 //=> <Buffer 00 00 00 00>
21
22 console.log(alloc(6, 0x41))
23 //=> <Buffer 41 41 41 41 41 41>
24
25 console.log(alloc(10, 'linus', 'utf8'))
26 //=> <Buffer 6c 69 6e 75 73 6c 69 6e 75 73>
27 ```
28
29 ## API
30
31 ### alloc(size[, fill[, encoding]])
32
33 - `size` &lt;Integer&gt; The desired length of the new `Buffer`
34 - `fill` &lt;String&gt; | &lt;Buffer&gt; | &lt;Integer&gt; A value to pre-fill the new `Buffer` with. **Default:** `0`
35 - `encoding` &lt;String&gt; If `fill` is a string, this is its encoding. **Default:** `'utf8'`
36
37 Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled.
38
39 ## See also
40
41 - [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
42 - [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
43 - [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`