# b4a

> Bridging the gap between buffers and typed arrays

Latest version **1.9.0** (published 2026-09-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install b4a
pnpm add b4a
yarn add b4a
bun add b4a
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.9.0 |
| Published | 2026-09-13 |
| First published | 2021-10-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | separate (@types/b4a) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 45.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 48 |
| Author | Holepunch |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/b4a
- Repository: https://github.com/holepunchto/b4a
- Homepage: https://github.com/holepunchto/b4a#readme
- Issues: https://github.com/holepunchto/b4a/issues
- npm.io page: https://npm.io/package/b4a

## Recent versions

- 1.9.0 (latest) — 2026-09-13
- 1.8.1 — 2026-04-30
- 1.8.0 — 2026-02-19
- 1.7.5 — 2026-02-17
- 1.7.4 — 2026-02-13
- 1.7.3 — 2025-09-26
- 1.7.2 — 2025-09-23
- 1.7.1 — 2025-09-11
- 1.7.0 — 2025-09-10
- 1.6.7 — 2024-09-25
- 1.6.6 — 2024-02-06
- 1.6.5 — 2024-02-06
- 1.6.4 — 2023-05-05
- 1.6.3 — 2023-03-17
- 1.6.2 — 2023-03-09
- … 18 more at https://npm.io/package/b4a/versions

## README

# Buffer for Array

Buffer for Array (B4A) provides a set of functions for bridging the gap between the Node.js `Buffer` class and the `Uint8Array` class. A browser compatibility layer is also included, making it possible to use B4A in both Node.js and browsers without having to worry about whether you're dealing with buffers or typed arrays.

## Installation

```sh
npm i b4a
```

### React Native

When imported from React Native `b4a` will make use of `react-native-b4a` for optimised buffer operations when available. All you need to do is install it:

```sh
npm i react-native-b4a
```

## API

#### `b4a.isBuffer(value)`

See https://nodejs.org/api/buffer.html#static-method-bufferisbufferobj

This will also return `true` when passed a `Uint8Array`.

#### `b4a.isEncoding(encoding)`

See https://nodejs.org/api/buffer.html#static-method-bufferisencodingencoding

#### `b4a.alloc(size[, fill[, encoding]])`

See https://nodejs.org/api/buffer.html#static-method-bufferallocsize-fill-encoding

#### `b4a.allocUnsafe(size)`

See https://nodejs.org/api/buffer.html#static-method-bufferallocunsafesize

#### `b4a.allocUnsafeSlow(size)`

See https://nodejs.org/api/buffer.html#static-method-bufferallocunsafeslowsize

#### `b4a.byteLength(string)`

See https://nodejs.org/api/buffer.html#static-method-bufferbytelengthstring-encoding

#### `b4a.compare(buf1, buf2)`

See https://nodejs.org/api/buffer.html#static-method-buffercomparebuf1-buf2

#### `b4a.concat(buffers[, totalLength])`

See https://nodejs.org/api/buffer.html#static-method-bufferconcatlist-totallength

#### `b4a.copy(source, target[, targetStart[, sourceStart[, sourceEnd]]])`

See https://nodejs.org/api/buffer.html#bufcopytarget-targetstart-sourcestart-sourceend

#### `b4a.equals(buf1, buf2)`

See https://nodejs.org/api/buffer.html#bufequalsotherbuffer

#### `b4a.fill(buffer, value[, offset[, end]][, encoding])`

See https://nodejs.org/api/buffer.html#buffillvalue-offset-end-encoding

#### `b4a.from(array)`

See https://nodejs.org/api/buffer.html#static-method-bufferfromarray

#### `b4a.from(arrayBuffer[, byteOffset[, length]])`

See https://nodejs.org/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length

#### `b4a.from(buffer)`

See https://nodejs.org/api/buffer.html#static-method-bufferfrombuffer

#### `b4a.from(string[, encoding])`

See https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding

#### `b4a.includes(buffer, value[, byteOffset][, encoding])`

See https://nodejs.org/api/buffer.html#bufincludesvalue-byteoffset-encoding

#### `b4a.indexOf(buffer, value[, byteOffset][, encoding])`

See https://nodejs.org/api/buffer.html#bufindexofvalue-byteoffset-encoding

#### `b4a.lastIndexOf(buffer, value[, byteOffset][, encoding])`

See https://nodejs.org/api/buffer.html#buflastindexofvalue-byteoffset-encoding

#### `b4a.swap16(buffer)`

See https://nodejs.org/api/buffer.html#bufswap16

#### `b4a.swap32(buffer)`

See https://nodejs.org/api/buffer.html#bufswap32

#### `b4a.swap64(buffer)`

See https://nodejs.org/api/buffer.html#bufswap64

#### `b4a.toBuffer(buffer)`

Convert a buffer to its canonical representation. In Node.js, the canonical representation is a `Buffer`. In the browser, the canonical representation is a `Uint8Array`.

#### `b4a.toString(buffer, [encoding[, start[, end]]])`

See https://nodejs.org/api/buffer.html#buftostringencoding-start-end

#### `b4a.write(buffer, string[, offset[, length]][, encoding])`

See https://nodejs.org/api/buffer.html#bufwritestring-offset-length-encoding

#### `b4a.writeDoubleLE(buffer, value[, offset])`

See https://nodejs.org/api/buffer.html#bufwritedoublelevalue-offset

#### `b4a.writeFloatLE(buffer, value[, offset])`

See https://nodejs.org/api/buffer.html#bufwritefloatlevalue-offset

#### `b4a.writeUInt32LE(buffer, value[, offset])`

https://nodejs.org/api/buffer.html#bufwriteuint32levalue-offset

#### `b4a.writeInt32LE(buffer, value[, offset])`

See https://nodejs.org/api/buffer.html#bufwriteint32levalue-offset

#### `b4a.readDoubleLE(buffer[, offset])`

See https://nodejs.org/api/buffer.html#bufreaddoubleleoffset

#### `b4a.readFloatLE(buffer[, offset])`

See https://nodejs.org/api/buffer.html#bufreadfloatleoffset

#### `b4a.readUInt32LE(buffer[, offset])`

See https://nodejs.org/api/buffer.html#bufreaduint32leoffset

#### `b4a.readInt32LE(buffer[, offset])`

See https://nodejs.org/api/buffer.html#bufreadint32leoffset

## License

Apache 2.0

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