UNPKG

999 BJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3
4function calcSizekb(size){
5 return `${Math.round((size / 1024) * 100) / 100}kb`;
6}
7
8exports.DirInfo = class DirInfo {
9 constructor(name, dirPath) {
10 this.name = name;
11 this.type = 'directory';
12 this.size = 0;
13 this.size_kb = 0;
14 this.path = dirPath;
15 this.absPath = path.resolve(dirPath);
16 this.dir = path.dirname(dirPath);
17 this.absDir = path.dirname(this.absPath);
18 this.dirNum = 0;
19 this.fileNum = 0;
20 this.children = [];
21 }
22}
23
24exports.FileInfo = class FileInfo {
25 constructor (name, filePath) {
26 const infos = path.parse(filePath);
27 this.name = name;
28 this.base = infos.name;
29 this.ext = infos.ext;
30 this.type = 'file';
31 this.size = fs.statSync(filePath).size;
32 this.size_kb = calcSizekb(this.size);
33 this.path = filePath;
34 this.absPath = path.resolve(filePath);
35 this.dir = infos.dir;
36 this.absDir = path.dirname(this.absPath);
37 }
38}
39
40exports.calcSizekb = calcSizekb;
\No newline at end of file