# to-array-buffer

> Convert any binary data to ArrayBuffer

Latest version **3.2.0** (published 2019-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-array-buffer
pnpm add to-array-buffer
yarn add to-array-buffer
bun add to-array-buffer
```

## 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 | 3.2.0 |
| Published | 2019-01-06 |
| First published | 2015-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Dima Yv |
| Maintainers | dfcreative, dy |
| Keywords | arraybuffer, array-buffer, array, buffer, binary, load, raw, load raw, data, blob, file |

## Links

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

## Dependencies (3)

- [is-blob](https://npm.io/package/is-blob.md) ^2.0.1
- [flatten-vertex-data](https://npm.io/package/flatten-vertex-data.md) ^1.0.2
- [string-to-arraybuffer](https://npm.io/package/string-to-arraybuffer.md) ^1.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 3.2.0 (latest) — 2019-01-06
- 3.1.1 — 2018-11-13
- 3.1.0 — 2018-11-13
- 3.0.0 — 2018-11-12
- 2.2.2 — 2018-11-11
- 2.2.1 — 2018-11-11
- 2.2.0 — 2018-11-11
- 2.1.0 — 2017-06-27
- 2.0.1 — 2017-06-19
- 2.0.0 — 2017-06-17
- 1.2.4 — 2017-04-12
- 1.2.3 — 2017-04-07
- 1.2.2 — 2017-03-18
- 1.2.1 — 2017-03-18
- 1.2.0 — 2015-12-30
- … 2 more at https://npm.io/package/to-array-buffer/versions

## README

# to-array-buffer [![unstable](https://img.shields.io/badge/stability-unstable-orange.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dy/to-array-buffer.svg)](https://travis-ci.org/dy/to-array-buffer)

Turn any binary data container into an _ArrayBuffer_ in sync way. Detected containers:

* Buffer
* TypedArray
* ArrayBufferView
* ArrayBuffer
* data-uri string
* base64 string
* plain string
* Array
* Array of Arrays
* Number (creates new ArrayBuffer of the defined length in bytes)
* etc.

It also handles some custom data types, like `ImageData`, `AudioBuffer` etc., but in general it returns `null` for objects not looking like binary data containers. Note also that it does not handle _Blob_ and _File_, since they require async API.

[![npm install to-array-buffer](https://nodei.co/npm/to-array-buffer.png?mini=true)](https://npmjs.org/package/to-array-buffer/)

```js
var toArrayBuffer = require('to-array-buffer')
var context = require('audio-context')

// Get array buffer from any object
ab = toArrayBuffer(new Buffer(100))
ab = toArrayBuffer(new Float32Array(12))
ab = toArrayBuffer(dataURIstr)
ab = toArrayBuffer(base64str)
ab = toArrayBuffer(ndarray)
ab = toArrayBuffer([[0, 1, 0], [1, 0, 1]])
```

### Related

* [to-arraybuffer](https://www.npmjs.com/package/to-arraybuffer) − convert Buffer to ArrayBuffer, fast implementation.
* [data-uri-to-buffer](https://npmjs.org/package/data-uri-to-buffer) − advanced data-uri decoder.
* [save-file](https://github.com/dy/save-file) — save any input data to file in node/browser.
* [buffer-to-arraybuffer](https://npmjs.org/package/buffer-to-arraybuffer) — convert surely known Buffer datatype to ArrayBuffer.

© Dmitry Yv 2018. MIT Licensed.

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