forked from enviPath/enviPy
Current Dev State
This commit is contained in:
16
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js
generated
vendored
Normal file
16
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js
generated
vendored
Normal 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
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/index.js
generated
vendored
Normal file
26
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/index.js
generated
vendored
Normal 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
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/readDir.js
generated
vendored
Normal file
8
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/readDir.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
function readDir(file, cb) {
|
||||
// do nothing for now
|
||||
cb(null, file);
|
||||
}
|
||||
|
||||
module.exports = readDir;
|
||||
13
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/streamFile.js
generated
vendored
Normal file
13
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getContents/streamFile.js
generated
vendored
Normal 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;
|
||||
19
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getStats.js
generated
vendored
Normal file
19
static/js/ketcher2/node_modules/vinyl-fs/lib/src/getStats.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var through2 = require('through2');
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
function getStats() {
|
||||
return through2.obj(fetchStats);
|
||||
}
|
||||
|
||||
function fetchStats(file, enc, cb) {
|
||||
fs.lstat(file.path, function (err, stat) {
|
||||
if (stat) {
|
||||
file.stat = stat;
|
||||
}
|
||||
cb(err, file);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = getStats;
|
||||
61
static/js/ketcher2/node_modules/vinyl-fs/lib/src/index.js
generated
vendored
Normal file
61
static/js/ketcher2/node_modules/vinyl-fs/lib/src/index.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
var defaults = require('defaults');
|
||||
var through = require('through2');
|
||||
var gs = require('glob-stream');
|
||||
var File = require('vinyl');
|
||||
|
||||
var getContents = require('./getContents');
|
||||
var getStats = require('./getStats');
|
||||
|
||||
function createFile (globFile, enc, cb) {
|
||||
cb(null, new File(globFile));
|
||||
}
|
||||
|
||||
function src(glob, opt) {
|
||||
opt = opt || {};
|
||||
var pass = through.obj();
|
||||
|
||||
if (!isValidGlob(glob)) {
|
||||
throw new Error('Invalid glob argument: ' + glob);
|
||||
}
|
||||
// return dead stream if empty array
|
||||
if (Array.isArray(glob) && glob.length === 0) {
|
||||
process.nextTick(pass.end.bind(pass));
|
||||
return pass;
|
||||
}
|
||||
|
||||
var options = defaults(opt, {
|
||||
read: true,
|
||||
buffer: true
|
||||
});
|
||||
|
||||
var globStream = gs.create(glob, options);
|
||||
|
||||
// when people write to use just pass it through
|
||||
var outputStream = globStream
|
||||
.pipe(through.obj(createFile))
|
||||
.pipe(getStats(options));
|
||||
|
||||
if (options.read !== false) {
|
||||
outputStream = outputStream
|
||||
.pipe(getContents(options));
|
||||
}
|
||||
|
||||
return outputStream.pipe(pass);
|
||||
}
|
||||
|
||||
function isValidGlob(glob) {
|
||||
if (typeof glob === 'string') {
|
||||
return true;
|
||||
}
|
||||
if (Array.isArray(glob) && glob.length !== 0) {
|
||||
return glob.every(isValidGlob);
|
||||
}
|
||||
if (Array.isArray(glob) && glob.length === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = src;
|
||||
Reference in New Issue
Block a user