# buffer-alloc

> A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.

Latest version **1.2.0** (published 2018-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install buffer-alloc
pnpm add buffer-alloc
yarn add buffer-alloc
bun add buffer-alloc
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-05-29 |
| First published | 2016-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Maintainers | linusu |
| Keywords | alloc, allocate, buffer alloc, buffer allocate, buffer |

## Links

- npm: https://www.npmjs.com/package/buffer-alloc
- Repository: https://github.com/LinusU/buffer-alloc
- Homepage: https://github.com/LinusU/buffer-alloc#readme
- Issues: https://github.com/LinusU/buffer-alloc/issues
- npm.io page: https://npm.io/package/buffer-alloc

## Dependencies (2)

- [buffer-fill](https://npm.io/package/buffer-fill.md) ^1.0.0
- [buffer-alloc-unsafe](https://npm.io/package/buffer-alloc-unsafe.md) ^1.1.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2018-05-29
- 1.1.0 — 2016-11-25
- 1.0.0 — 2016-11-22
- 0.1.1 — 2016-08-21
- 0.1.0 — 2016-08-18

## README

# Buffer Alloc

A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.

Works as Node.js: `v7.0.0` <br>
Works on Node.js: `v0.10.0`

## Installation

```sh
npm install --save buffer-alloc
```

## Usage

```js
const alloc = require('buffer-alloc')

console.log(alloc(4))
//=> <Buffer 00 00 00 00>

console.log(alloc(6, 0x41))
//=> <Buffer 41 41 41 41 41 41>

console.log(alloc(10, 'linus', 'utf8'))
//=> <Buffer 6c 69 6e 75 73 6c 69 6e 75 73>
```

## API

### alloc(size[, fill[, encoding]])

- `size` &lt;Integer&gt; The desired length of the new `Buffer`
- `fill` &lt;String&gt; | &lt;Buffer&gt; | &lt;Integer&gt; A value to pre-fill the new `Buffer` with. **Default:** `0`
- `encoding` &lt;String&gt; If `fill` is a string, this is its encoding. **Default:** `'utf8'`

Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled.

## See also

- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
- [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`

---
_Source: https://npm.io/package/buffer-alloc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
