Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blob-to-buffer

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blob-to-buffer - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

33

index.js

@@ -0,17 +1,34 @@

/* global Blob, FileReader */
// arraybuffer -> buffer without copy
var toBuffer = require('typedarray-to-buffer')
module.exports = function blobToBuffer (blob, cb) {
if (typeof Blob === 'undefined' || !(blob instanceof Blob))
if (typeof Blob === 'undefined' || !(blob instanceof Blob)) {
throw new Error('first argument must be a Blob')
if (typeof cb !== 'function')
}
if (typeof cb !== 'function') {
throw new Error('second argument must be a function')
}
var reader = new FileReader()
reader.addEventListener('load', function (e) {
// uint8array -> buffer without copy
var buffer = toBuffer(new Uint8Array(e.target.result))
cb(null, buffer)
})
reader.addEventListener('error', cb)
function onLoad (e) {
unregisterEvents()
cb(null, toBuffer(e.target.result))
}
function onError (err) {
unregisterEvents()
cb(err)
}
function unregisterEvents () {
reader.removeEventListener('load', onLoad)
reader.removeEventListener('error', onError)
}
reader.addEventListener('load', onLoad)
reader.addEventListener('error', onError)
reader.readAsArrayBuffer(blob)
}
{
"name": "blob-to-buffer",
"description": "Convert a Blob to a Buffer",
"version": "1.2.1",
"version": "1.2.2",
"author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)",

@@ -13,2 +13,3 @@ "bugs": {

"devDependencies": {
"standard": "^3.8.0",
"tape": "^4.0.0",

@@ -32,3 +33,3 @@ "zuul": "^3.0.0"

"scripts": {
"test": "zuul -- test/*.js"
"test": "standard && zuul -- test/*.js"
},

@@ -35,0 +36,0 @@ "testling": {

@@ -0,1 +1,3 @@

/* global Blob */
var toBuffer = require('../')

@@ -14,3 +16,2 @@ var test = require('tape')

test('Callback error on invalid arguments', function (t) {

@@ -17,0 +18,0 @@ t.throws(function () {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc