Skip to content

Commit

Permalink
Add mode more attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 27, 2018
1 parent deeaf7e commit f9e1d82
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ readdir('/').then((files) => {
// output =>
// Stats {
// dev: 16777220,
// mode: 16877,
// mode: {
// number: 16877,
// string: 'drwxr-xr-x',
// owner: { read: true, write: true, execute: true },
// group: { read: true, write: false, execute: true },
// others: { read: true, write: false, execute: true }
// },
// nlink: 26,
// uid: 0,
// gid: 0,
Expand Down Expand Up @@ -60,7 +66,13 @@ getStat('/var').then((Stats) => {
// output =>
// Stats {
// dev: 16777220,
// mode: 16877,
// mode: {
// number: 16877,
// string: 'drwxr-xr-x',
// owner: { read: true, write: true, execute: true },
// group: { read: true, write: false, execute: true },
// others: { read: true, write: false, execute: true }
// },
// nlink: 26,
// uid: 0,
// gid: 0,
Expand Down
24 changes: 17 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
const fs = require('fs');
const path = require('path');
const nicki = require('nicki');
const Mode = require('stat-mode');

exports.getStat = async (currentPath, names) => {
if (!names) names = await this.uidToName();
return new Promise((resolve, reject) => {
fs.stat(currentPath, (err, data) => {
fs.stat(currentPath, (err, stat) => {
if (err) reject(err);
else {
if (names && names[data.uid]) {
data.uidToName = names[data.uid];
const mode = new Mode(stat);
if (names && names[stat.uid]) {
stat.uidToName = names[stat.uid];
}
data.path = currentPath;
data.basename = path.basename(currentPath);
data.extname = path.extname(data.basename);
resolve(data);
stat.mode = {
number: stat.mode,
string: mode.toString(),
owner: { ...mode.owner },
group: { ...mode.group },
others: { ...mode.others },
};
// stat.modeStr = mode.toString();
stat.path = currentPath;
stat.basename = path.basename(currentPath);
stat.extname = path.extname(stat.basename);
resolve(stat);
};
})
});
Expand Down
9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"author": "kenny",
"license": "MIT",
"dependencies": {
"nicki": "^3.0.1"
"nicki": "^3.0.1",
"stat-mode": "^0.2.2"
}
}

0 comments on commit f9e1d82

Please sign in to comment.