A new start

This commit is contained in:
2018-11-24 14:43:59 +01:00
commit 3c32c8a37a
24054 changed files with 1376258 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
'use strict';
var fs = require('graceful-fs');
var stripBom = require('strip-bom');
function bufferFile(file, cb) {
fs.readFile(file.path, function (err, data) {
if (err) {
return cb(err);
}
file.contents = stripBom(data);
cb(null, file);
});
}
module.exports = bufferFile;
+26
View File
@@ -0,0 +1,26 @@
'use strict';
var through2 = require('through2');
var readDir = require('./readDir');
var bufferFile = require('./bufferFile');
var streamFile = require('./streamFile');
function getContents(opt) {
return through2.obj(function (file, enc, cb) {
// don't fail to read a directory
if (file.isDirectory()) {
return readDir(file, cb);
}
// read and pass full contents
if (opt.buffer !== false) {
return bufferFile(file, cb);
}
// dont buffer anything - just pass streams
return streamFile(file, cb);
});
}
module.exports = getContents;
+8
View File
@@ -0,0 +1,8 @@
'use strict';
function readDir(file, cb) {
// do nothing for now
cb(null, file);
}
module.exports = readDir;
+13
View File
@@ -0,0 +1,13 @@
'use strict';
var fs = require('graceful-fs');
var stripBom = require('strip-bom');
function streamFile(file, cb) {
file.contents = fs.createReadStream(file.path)
.pipe(stripBom.stream());
cb(null, file);
}
module.exports = streamFile;