# @craftzdog/react-native-buffer

> Node.js Buffer API, for React Native

Latest version **6.1.2** (published 2026-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @craftzdog/react-native-buffer
pnpm add @craftzdog/react-native-buffer
yarn add @craftzdog/react-native-buffer
bun add @craftzdog/react-native-buffer
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 6.1.2 |
| Published | 2026-05-08 |
| First published | 2021-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 81.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 134 |
| Author | Feross Aboukhadijeh |
| Maintainers | craftzdog |
| Keywords | arraybuffer, browser, browserify, buffer, compatible, dataview, uint8array |

## Links

- npm: https://www.npmjs.com/package/@craftzdog/react-native-buffer
- Repository: https://github.com/craftzdog/react-native-buffer
- Issues: https://github.com/craftzdog/react-native-buffer/issues
- Funding: https://github.com/sponsors/feross
- npm.io page: https://npm.io/package/@craftzdog/react-native-buffer

## Dependencies (2)

- [ieee754](https://npm.io/package/ieee754.md) ^1.2.1
- [react-native-quick-base64](https://npm.io/package/react-native-quick-base64.md) ^3.0.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 6.1.2 (latest) — 2026-05-08
- 6.1.1 — 2025-10-03
- 6.1.0 — 2025-05-27
- 6.0.5 — 2022-07-22
- 6.0.4 — 2022-01-21
- 6.0.3 — 2021-02-09

## README

# @craftzdog/react-native-buffer

#### The buffer module from [node.js](https://nodejs.org/), for React Native.

Simply `require('@craftzdog/react-native-buffer')` or use the `Buffer` global and you will get this module.
It internally uses [react-native-quick-base64](https://github.com/craftzdog/react-native-quick-base64), which is a performant native implementation of base64.

The goal is to provide an API that is 100% identical to
[node's Buffer API](https://nodejs.org/api/buffer.html). Read the
[official docs](https://nodejs.org/api/buffer.html) for the full list of properties,
instance methods, and class methods that are supported.

## features

- Manipulate binary data like a boss, in all browsers!
- Super fast. Backed by Typed Arrays (`Uint8Array`/`ArrayBuffer`, not `Object`)
- Extremely small bundle size (**6.75KB minified + gzipped**, 51.9KB with comments)
- Excellent browser support (Chrome, Firefox, Edge, Safari 11+, iOS 11+, Android, etc.)
- Preserves Node API exactly
- Square-bracket `buf[4]` notation works!
- Does not modify any browser prototypes or put anything on `window`
- Comprehensive test suite (including all buffer tests from node.js core)

## install

```bash
npm install @craftzdog/react-native-buffer react-native-quick-base64
cd ios && pod install
```

## usage

The module's API is identical to node's `Buffer` API. Read the
[official docs](https://nodejs.org/api/buffer.html) for the full list of properties,
instance methods, and class methods that are supported.

To depend on this module explicitly, require it like this:

```js
import { Buffer } from "@craftzdog/react-native-buffer";
```

## how does it work?

The Buffer constructor returns instances of `Uint8Array` that have their prototype
changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of `Uint8Array`,
so the returned instances will have all the node `Buffer` methods and the
`Uint8Array` methods. Square bracket notation works as expected -- it returns a
single octet.

The `Uint8Array` prototype remains unmodified.

## conversion packages

### convert typed array to buffer

Use [`typedarray-to-buffer`](https://www.npmjs.com/package/typedarray-to-buffer) to convert any kind of typed array to a `Buffer`. Does not perform a copy, so it's super fast.

### convert buffer to typed array

`Buffer` is a subclass of `Uint8Array` (which is a typed array). So there is no need to explicitly convert to typed array. Just use the buffer as a `Uint8Array`.

### convert blob to buffer

Use [`blob-to-buffer`](https://www.npmjs.com/package/blob-to-buffer) to convert a `Blob` to a `Buffer`.

### convert buffer to blob

To convert a `Buffer` to a `Blob`, use the `Blob` constructor:

```js
var blob = new Blob([buffer]);
```

Optionally, specify a mimetype:

```js
var blob = new Blob([buffer], { type: "text/html" });
```

### convert arraybuffer to buffer

To convert an `ArrayBuffer` to a `Buffer`, use the `Buffer.from` function. Does not perform a copy, so it's super fast.

```js
var buffer = Buffer.from(arrayBuffer);
```

### convert buffer to arraybuffer

To convert a `Buffer` to an `ArrayBuffer`, use the `.buffer` property (which is present on all `Uint8Array` objects):

```js
var arrayBuffer = buffer.buffer.slice(
  buffer.byteOffset,
  buffer.byteOffset + buffer.byteLength
);
```

Alternatively, use the [`to-arraybuffer`](https://www.npmjs.com/package/to-arraybuffer) module.

## performance

4x faster than base64-js on an iPhone 11 Pro when dealing with base64, thanks to [react-native-quick-base64](https://github.com/craftzdog/react-native-quick-base64).

## Testing the project

First, install the project:

    npm install

Then, to run tests in Node.js, run:

    npm run test-node

To test locally in a browser, you can run:

    npm run test-browser-old-local # For ES5 browsers that don't support ES6
    npm run test-browser-new-local # For ES6 compliant browsers

This will print out a URL that you can then open in a browser to run the tests, using [airtap](https://www.npmjs.com/package/airtap).

To run automated browser tests using Saucelabs, ensure that your `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables are set, then run:

    npm test

This is what's run in Travis, to check against various browsers. The list of browsers is kept in the `bin/airtap-es5.yml` and `bin/airtap-es6.yml` files.

## JavaScript Standard Style

This module uses [JavaScript Standard Style](https://github.com/feross/standard).

[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

To test that the code conforms to the style, `npm install` and run:

## Credit

This was originally forked from [feross/buffer](https://github.com/feross/buffer).

## Security Policies and Procedures

The `buffer` team and community take all security bugs in `buffer` seriously. Please see our [security policies and procedures](https://github.com/feross/security) document to learn how to report issues.

## license

MIT.
Copyright (C) [Takuya Matsuyama](https://www.craftz.dog/), and other contributors.
Originally forked from an MIT-licensed module by [Feross Aboukhadijeh](http://feross.org) and Romain Beauxis.

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