UNPKG

659 BJavaScriptView Raw
1'use strict';
2const Api = require('./api');
3
4const ENC_TYPE = configSize => configSize > 1 ? 'encode' : 'encodeSync';
5
6class DataURI extends Api {
7 constructor() {
8 super();
9
10 const configSize = arguments.length;
11
12 if (configSize) {
13 this[ENC_TYPE(configSize)].apply(this, arguments);
14 }
15 }
16
17 static promise(fileName) {
18 const datauri = new DataURI();
19
20 return new Promise((resolve, reject) => {
21 datauri.on('encoded', resolve)
22 .on('error', reject)
23 .encode(fileName);
24 });
25 }
26
27 static sync(fileName) {
28 const datauri = new DataURI(fileName);
29
30 return datauri.content;
31 }
32}
33
34module.exports = DataURI;