diff --git a/README.md b/README.md index a48b332..73509e9 100644 --- a/README.md +++ b/README.md @@ -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, @@ -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, diff --git a/index.js b/index.js index 8e3bc69..f874250 100644 --- a/index.js +++ b/index.js @@ -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); }; }) }); diff --git a/package-lock.json b/package-lock.json index 04ad9b6..165ef50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "dir-reader", - "version": "1.0.0", + "name": "reader-stat", + "version": "1.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -211,6 +211,11 @@ "win32": "^2.0.0" } }, + "stat-mode": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/stat-mode/-/stat-mode-0.2.2.tgz", + "integrity": "sha1-5sgLYjEj19gM8TLOU480YokHJQI=" + }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", diff --git a/package.json b/package.json index 4f9ba7c..38c72b7 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "author": "kenny", "license": "MIT", "dependencies": { - "nicki": "^3.0.1" + "nicki": "^3.0.1", + "stat-mode": "^0.2.2" } }