-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
31 lines (22 loc) · 816 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
31
'use strict';
var jscrush = require('jscrush');
var through = require('through2');
var BufferStreams = require('bufferstreams');
module.exports = function () {
return through.obj(function (file, enc, callback) {
if (file.isBuffer()) {
var crushed = jscrush(String(file.contents));
file.contents = new Buffer(crushed);
}
if (file.isStream()) {
var bufferStream = new BufferStreams(function (err, buffer, callback) {
if (err) this.emit('error', err);
var crushed = jscrush(buffer.toString('utf8'));
callback(null, new Buffer(crushed));
}.bind(this));
file.contents = file.contents.pipe(bufferStream);
}
this.push(file);
return callback();
});
};