StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
StackGenVis/frontend/node_modules/file-contents/index.js

133 lines
2.5 KiB

'use strict';
var utils = require('./utils');
/**
* Add the `contents` property to a `file` object.
*
* @param {Object} `options`
* @return {Object} File object.
*/
module.exports = function fileContents(options) {
return utils.through.obj(function (file, enc, next) {
async(file, options, function (err, res) {
if (err) {
next(err);
return;
}
next(null, res);
});
});
};
/**
* Async method for getting `file.contents`.
*
* @param {Object} `file`
* @param {Object} `options`
* @param {Function} `cb`
* @return {Object}
*/
function async(file, options, cb) {
if (typeof file !== 'object') {
throw new TypeError('expected file to be an object');
}
if (typeof options === 'function') {
cb = options;
options = {};
}
if (typeof cb !== 'function') {
throw new TypeError('expected callback to be a function');
}
if (!file.stat) {
return utils.stats.getStats(file, function (err, res) {
if (err) return cb(err);
async(res, options, cb);
});
}
try {
if (file.stat.isDirectory()) {
return cb(null, file);
}
} catch(err) {
return cb(err);
}
var opts = utils.extend({}, options, file.options || {});
if (opts.noread === true || opts.read === false) {
return cb(null, file);
}
if (opts.buffer !== false) {
return utils.fs.readFile(file.path, function(err, data) {
if (err) return cb(err);
file.contents = utils.stripBom(data);
cb(null, file);
});
}
try {
file.contents = utils.fs.createReadStream(file.path);
cb(null, file);
} catch (err) {
cb(err);
}
}
/**
* Sync method for getting `file.contents`.
*
* @param {Object} `file`
* @param {Object} `options`
* @return {Object}
*/
function sync(file, options) {
if (typeof file !== 'object') {
throw new TypeError('expected file to be an object.');
}
if (!file.stat) {
file.stat = utils.fs.lstatSync(file.path);
}
if (file.stat.isDirectory()) {
return file;
}
var opts = utils.extend({}, options, file.options);
if (opts.noread === true || opts.read === false) {
return file;
}
if (opts.buffer !== false) {
file.contents = utils.stripBom(utils.fs.readFileSync(file.path));
return file;
}
try {
file.contents = utils.fs.createReadStream(file.path);
return file;
} catch (err) {
throw err;
}
}
/**
* Expose `async` method
*/
module.exports.async = async;
/**
* Expose `sync` method
*/
module.exports.sync = sync;