-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
30 lines (26 loc) · 668 Bytes
/
index.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
var gs = require('glob-stream'),
fs = require('fs'),
through = require('through2'),
png = require('png-js');
module.exports = function (glob, decode) {
var write = decodeFiles;
if (decode === false) {
write = passthru;
}
return gs(glob).pipe(through({ objectMode: true }, write));
function decodeFiles(chunk, enc, next) {
var self = this;
png.decode(chunk.path, function(pixels) {
self.push(pixels);
next();
});
}
function passthru(chunk, enc, next) {
var self = this;
fs.createReadStream(chunk.path)
.on('data', function (data) {
self.push(data);
})
.on('end', next);
}
};