
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
fetch-base64-in-browser
Advanced tools
fetch-base64-in-browser
fetches binary files on the web and converts them to either a Base64 string or a data uri (which is a base64 string with some prefixed data)
my original intent was to be able to catch short mp3 clips into localstorage since ios safari doesn't seem to cache audio directly.
apparently the reason for writing this (getting around some mobile safari/ios issues) is now also disabled because of changes webkit made over the summer. this is probably not as useful anymore :|
those functions only convert strings into base64
npm install fetch-base64-in-browser
<html>
<head>
<script src="../lib/fetch-base64.js"></script>
<script>
'use strict';
document.addEventListener('DOMContentLoaded', function(event) {
let b64f = new FetchBase64('./spongebob.png');
b64f.fetchAsData().then((base64) => {
console.log('spongebob.png is b64', base64);
document.getElementById('spongebob').src = base64;
}).catch((err) => {
console.error(err);
})
})
</script>
</head>
<body>
<img id="spongebob" />
</body>
</html>
your browser needs to support
browsers that match this criteria
ie is not supported at all.
the constructor allows for you to pass shims for fetch and FileReader, thus theoretically making this work for node.js as well.
the two npm libraries used to test for this were:
node-fetch
for fetch api@swang/filereader
for the filereader api (i am using this fork because the original one is not kept up to date and more work needed to be done to support blobs)create a new instance of the class
url (string): the url that you want to fetch opts (object): you pass a shims object that contains the fetch and filereader shims you want to use instead of the browsers apis (or node's lack of apis)
const fileReader = require('@swang/filereader')
const fetch = require('node-fetch')
const FetchBase64 = require('fetch-base64-in-browser')
const url = 'https://raw.githubusercontent.com/github/explore/fd96fceccf8c42c99cbe29cf0f8dcc4736fcb85a/topics/nodejs/nodejs.png'
let shims = {
fetch,
fileReader
}
let b64f = new FetchBase64(url, { shims })
b64.fetchAsData().then((base64) => console.log(base64))
fetches a url and returns its base64 value
url(string): the url you want to convert to its base64 value opts(object): this passes the same parameters as a normal fetch would.
see [https://developers.google.com/web/updates/2015/03/introduction-to-fetch](google's intro to fetch) for a small list of available options
same as fetch
, but returns a data uri
isc
shuan wang (shuanwang@gmail.com)
FAQs
Fetch data as base64 using only browser functions
The npm package fetch-base64-in-browser receives a total of 1 weekly downloads. As such, fetch-base64-in-browser popularity was classified as not popular.
We found that fetch-base64-in-browser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.