November: Procrastination Month

    to-array-buffer

    3.2.0 • Public • Published

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

    Related

    © Dmitry Yv 2018. MIT Licensed.

    Install

    npm i to-array-buffer

    DownloadsWeekly Downloads

    157,448

    Version

    3.2.0

    License

    MIT

    Unpacked Size

    9.55 kB

    Total Files

    6

    Last publish

    Collaborators

    • dfcreative
    • dy