New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

binary-base64

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-base64

This is a base64 encoding/decoding library.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

binary-base64

This is a base64 encoding/decoding library.

Install

$ npm install binary-base64 --save

Usage

import base64 from 'binary-base64';

async function getDataUri(uri) {
  const response = await fetch(uri);
  const buffer = new Uint8Array(await response.arrayBuffer());
  const type = response.headers.get('content-type');
  return `data:${type};base64,${base64.encode(buffer)}`;
}

function getBlobFromDataUri(uri) {
  return new Promise(function(resolve, reject) {
    const [ , type, base64EncodedString ] = uri.match('data:([^;]+);base64,(.+)') || [];
    if (typeof type === 'undefined' && typeof base64EncodedString === 'undefined') {
      return reject(new TypeError('Invalid data URI.'));
    }
    return resolve(new Blob([base64.decode(base64EncodedString)], { type }));
  });
}

(async function() {
  const dataUri = await getDataUri('https://www.gravatar.com/avatar/b9025074d487cd0328f1dc816e5ac50a.jpg');
  console.log(dataUri);
  const blob = await getBlobFromDataUri(dataUri);
  console.log(URL.createObjectURL(blob));
})();

Keywords

FAQs

Package last updated on 14 Dec 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc