all files / file-manager-js/lib/ info.js

100% Statements 17/17
100% Branches 2/2
100% Functions 0/0
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                        
const stat = require('./stat');
const dirSize = require('./dirSize');
 
// gets an extended stats object from stats
const info = (fsReaddir, fsStat, join) => {
  const statFn = stat(fsStat);
  const dirSizeFn = dirSize(fsReaddir, fsStat, join);
 
  return (path) => {
    let infoObj = {};
    return statFn(path)
      .then((stats) => {
        infoObj = Object.assign({}, stats);
        if (stats.isFile()) {
          infoObj.type = 'file';
          return stats.size;
        }
        infoObj.type = 'directory';
        return dirSizeFn(path);
      })
      .then((sz) => {
        infoObj.size = sz;
        return infoObj;
      });
  };
};
 
module.exports = info;