You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.1KB

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