An open API service indexing awesome lists of open source software.

https://github.com/neilblaze/buffer2url

Creates a data URL (base64-encoded) from a Buffer and a mimetype for Node.js
https://github.com/neilblaze/buffer2url

Last synced: 3 months ago
JSON representation

Creates a data URL (base64-encoded) from a Buffer and a mimetype for Node.js

Awesome Lists containing this project

README

          

# buffer2url | @npm_node.js

License
Build status Commits since v1.0.0 Last commit Issues
Latest version on npm Downloads

**Creates a data URL (base64-encoded) from a Buffer and a mimetype for Node.js.**

## Installation

buffer2url on npm

```bash
npm install --save buffer2url@^1.0.0
```

buffer2url on Yarn

```bash
yarn add buffer2url@^1.0.0
```

@Neilblaze/buffer2url on GitHub Packages
(if [configured properly](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages))

```bash
npm install --save @Neilblaze/buffer2url@^1.0.0
```

## Example

```javascript
import buffer2url from "buffer2url"

const imageBuffer = fs.readFileSync("pikachu_8x8.png")
const dataUrl = buffer2Url("image/png", imageBuffer)
```

Variable `result` will be:

```javascript
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAARklEQVQoU2P8/Z/hPwMewEiUAhaG/wyMjIwMv6FmIfPBJrAyQuyAKUDmo1iBrhCkifG/oBrY4D/vbqE4lUVIDcwnrICQLwAWoihJ/lJMVwAAAABJRU5ErkJgggAA"
```

## Development

Setting up:
```bash
git clone git@github.com:Neilblaze/buffer2url.git
cd buffer2url
npm install
```
Testing:
```bash
npm run test:dev
```
Testing in production environment:
```bash
npm run test
```

## License
[MIT License](https://raw.githubusercontent.com/Neilblaze/buffer2url/master/license.txt)
Copyright © 2020, Neilblaze \ (https://github.com/Neilblaze)