buffer-to-data-url
v1.0.0
Published
Creates a base64-encoded data URL from a Buffer and a mimetype.
Downloads
1,777
Readme
buffer-to-data-url
Creates a base64-encoded data URL from a Buffer and a mimetype.
Installation
npm install --save buffer-to-data-url@^1.0.0
yarn add buffer-to-data-url@^1.0.0
(if configured properly)
npm install --save @jaid/buffer-to-data-url@^1.0.0
Example
import bufferToDataUrl from "buffer-to-data-url"
const imageBuffer = fs.readFileSync("pikachu_8x8.png")
const dataUrl = bufferToDataUrl("image/png", imageBuffer)
Variable result
will be:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAARklEQVQoU2P8/Z/hPwMewEiUAhaG/wyMjIwMv6FmIfPBJrAyQuyAKUDmo1iBrhCkifG/oBrY4D/vbqE4lUVIDcwnrICQLwAWoihJ/lJMVwAAAABJRU5ErkJgggAA"
Development
Setting up:
git clone [email protected]:jaid/buffer-to-data-url.git
cd buffer-to-data-url
npm install
Testing:
npm run test:dev
Testing in production environment:
npm run test
License
MIT License
Copyright © 2020, Jaid <[email protected]> (https://github.com/jaid)