-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (32 loc) · 878 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
32
33
34
35
36
37
38
39
40
'use strict';
const concatStream = require('concat-stream');
const rmlines = require('rmlines');
const intoStream = require('into-stream');
const through = require('through2');
const self = {};
const transfromStream = function (file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isBuffer()) {
const stream = intoStream(file.contents);
stream.pipe(rmlines(self.lines, self.opts)).pipe(concatStream(data => {
file.contents = Buffer.from(data);
cb(null, file);
}));
return;
}
if (file.isStream()) {
file.contents = file.contents.pipe(rmlines(self.lines, self.opts));
return cb(null, file);
}
return cb(null, file);
};
const endStream = function (cb) {
cb();
};
module.exports = function (lines, opts) {
self.lines = (lines) ? lines : [];
self.opts = (opts) ? opts : {};
return through.obj(transfromStream, endStream);
};