1.5.1 • Published 2 years ago
dirent-from-stats v1.5.1
dirent-from-stats
Create fs.Dirents from fs.Stats for compatiblity on earlier versions of Node.js.
It will inherit from fs.Dirent if it exists; otherwise, it will create a new base Dirent class.
var assert = require('assert');
var DirentFromStats = require('dirent-from-stats');
var fs = require('fs');
var each = require('async-each');
var DirentBase = DirentFromStats.DirentBase;
var TEST_DIR = path.resolve(path.join(__dirname, '..', '..', '.tmp', 'test'));
function create(root, name, callback) {
return fs.lstat(path.join(root, name), function (err, stats) {
err ? callback(err) : callback(null, new DirentFromStats(name, stats));
});
}
fs.readdir(__dirname, function (err, names) {
each(names, create.bind(null, TEST_DIR), function (err, dirents) {
for (var index in dirents) {
assert.ok(dirents[index] instanceof DirentBase);
assert.ok(!fs.Dirent || dirents[index] instanceof fs.Dirent);
}
}
}