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.6KB

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