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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Buffer Alloc Unsafe
  2. A [ponyfill](https://ponyfill.com) for `Buffer.allocUnsafe`.
  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-unsafe
  8. ```
  9. ## Usage
  10. ```js
  11. const allocUnsafe = require('buffer-alloc-unsafe')
  12. console.log(allocUnsafe(10))
  13. //=> <Buffer 78 0c 80 03 01 00 00 00 05 00>
  14. console.log(allocUnsafe(10))
  15. //=> <Buffer 58 ed bf 5f ff 7f 00 00 01 00>
  16. console.log(allocUnsafe(10))
  17. //=> <Buffer 50 0c 80 03 01 00 00 00 0a 00>
  18. allocUnsafe(-10)
  19. //=> RangeError: "size" argument must not be negative
  20. ```
  21. ## API
  22. ### allocUnsafe(size)
  23. - `size` &lt;Integer&gt; The desired length of the new `Buffer`
  24. Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must be
  25. less than or equal to the value of `buffer.kMaxLength` and greater than or equal
  26. to zero. Otherwise, a `RangeError` is thrown.
  27. ## See also
  28. - [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
  29. - [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
  30. - [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`