UNPKG

706 BJavaScriptView Raw
1const fs = require('fs');
2const util = require('util');
3const Streamz = require('streamz');
4
5function File(file,options) {
6 if (!(this instanceof File))
7 return new File(file,options);
8
9 Streamz.call(this);
10
11 options = options || {};
12 if (options.encoding === undefined)
13 options.encoding = 'utf-8';
14
15 fs.createReadStream(file,options)
16 .pipe(this);
17
18 let filename = file.split('/');
19 filename = filename[filename.length-1];
20
21 this.info = options.info || {};
22 this.info.__path = file;
23 this.info.__filename = filename;
24}
25
26util.inherits(File,Streamz);
27
28File.prototype._fn = function(d) {
29 const obj = Object.create(this.info);
30 obj.text = d;
31 this.push(obj);
32};
33
34module.exports = File;
\No newline at end of file