blob-to-buffer
![javascript style guide](https://camo.githubusercontent.com/bde227e3207c7143032c0feb73889ffbda8eb1ef234b820b915ccaf74f9c66d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64655f7374796c652d7374616e646172642d627269676874677265656e2e737667)
Convert a Blob to a Buffer.
Say you're using the 'buffer' module on npm, or browserify and you're working with lots of binary data.
Unfortunately, sometimes the browser or someone else's API gives you a Blob
. Silly browser. How do you convert it to a Buffer
?
Something with a goofy FileReader
thingy... Time to Google for it yet again... There must be a better way!
There is! Simply use this module!
Works in the browser. This module is used by WebTorrent!
install
npm install blob-to-buffer
usage
var toBuffer = require('blob-to-buffer')
// Get a Blob somehow...
var blob = new Blob([ new Uint8Array([1, 2, 3]) ], { type: 'application/octet-binary' })
toBuffer(blob, function (err, buffer) {
if (err) throw err
buffer[0] // => 1
buffer.readUInt8(1) // => 2
})
license
MIT. Copyright (c) Feross Aboukhadijeh.