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

100% Statements 13/13
100% Branches 2/2
100% Functions 0/0
100% Lines 12/12
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                               
/**
 * file-manager-js/info
 * @copyright 2018 Eyas Ranjous <eyas.ranjous@gmail.com>
 * @license MIT
 */
 
// gets an extended stats object from stats
const hof = (stat, dirSize) => (path) => {
  let info = {};
  return stat(path)
    .then((stats) => {
      info = Object.assign({}, stats);
      if (stats.isFile()) {
        info.type = 'file';
        return stats.size;
      }
      info.type = 'directory';
      return dirSize(path);
    })
    .then((sz) => {
      info.size = sz;
      return info;
    });
};
 
module.exports = hof;