https://github.com/parro-it/file-to-datauri
Convert local files into data uris with ease.
https://github.com/parro-it/file-to-datauri
Last synced: 7 months ago
JSON representation
Convert local files into data uris with ease.
- Host: GitHub
- URL: https://github.com/parro-it/file-to-datauri
- Owner: parro-it
- License: mit
- Created: 2015-08-20T18:43:22.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-20T19:32:14.000Z (over 10 years ago)
- Last Synced: 2024-10-13T02:51:42.012Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 117 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# file-to-datauri
Convert local files into data uris with ease.
## Installation
```bash
npm install --save file-to-datauri
```
## How it works
Read the file, either sync or async, find mime
using file extension, and return file content
encoded as data-uri.
Only support utf8 encoded files.
## Usage
```javascript
import datauri from 'file-to-datauri'
// use with a callback
datauri(__dirname + '/some/file.txt', (err, uri) => {
if (err) {
return;
}
console.log(uri);
});
// use with promise (if no callback given)
(async () => {
const uri = datauri(__dirname + '/some/file.txt');
console.log(uri);
})();
// use sync
const uri = datauri.sync(__dirname + '/some/file.txt');
console.log(uri);
```
## Credits
Inspired by [data-uri](https://github.com/mcwhittemore/data-uri)
## License
The MIT License (MIT)
Copyright (c) 2015 Andrea Parodi