Socket
Socket
Sign inDemoInstall

to-array-buffer

Package Overview
Dependencies
6
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    to-array-buffer

Convert any binary data to ArrayBuffer


Version published
Maintainers
2
Install size
49.7 kB
Created

Readme

Source

to-array-buffer unstable Build Status

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

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]])

© Dmitry Yv 2018. MIT Licensed.

Keywords

FAQs

Last updated on 06 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc