/
purify.js
64 lines (49 loc) · 1.13 KB
/
purify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* imacss
*
* Copyright(c) 2014 André König <andre.koenig@posteo.de>
* MIT Licensed
*
*/
/**
* @author André König <andre.koenig@posteo.de>
*
*/
'use strict';
var stream = require('stream');
var util = require('util');
var path = require('path');
/**
* The stream which will convert the vinyl file to
* an internal image data structure.
*
* @param {object} options Stream options.
*
*/
function Purify (options) {
options = options || {};
options.objectMode = true;
stream.Transform.call(this, options);
}
util.inherits(Purify, stream.Transform);
/**
* The transformation process.
*
*/
Purify.prototype._transform = function _transform (vfile, enc, cb) {
var image = {};
if (!vfile.contents) {
return cb(new Error('Please define a valid glob, which will find some image files.'));
}
//
// Converting the vinyl file into an own data model.
//
image.name = path.basename(vfile.path);
image.contents = vfile.contents;
image.base64 = vfile.contents.toString('base64');
this.push(image);
cb();
};
module.exports = function () {
return new Purify();
};