diff --git a/README.md b/README.md index dd54ada..41a9ea7 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ npm install reader-stat --save ## Usage +### readdir + ```js const { readdir } = require('reader-stat'); @@ -22,14 +24,7 @@ readdir('/').then((files) => { // output => // Stats { // dev: 16777220, - // mode: { - // number: 16877, - // string: 'drwxr-xr-x', - // isSymbolicLink: true, - // owner: { read: true, write: true, execute: true }, - // group: { read: true, write: false, execute: true }, - // others: { read: true, write: false, execute: true } - // }, + // mode: 41453, // nlink: 26, // uid: 0, // gid: 0, @@ -46,15 +41,25 @@ readdir('/').then((files) => { // mtime: 2017-09-26T05:32:50.874Z, // ctime: 2017-09-26T05:32:50.874Z, // birthtime: 2017-09-26T05:08:14.000Z, - // uidToName: 'root', - // path: '/var', - // basename: 'var', - // extname: '' + // extend: { + // number: 41453, + // isSymbolicLink: true, + // string: 'lrwxr-xr-x', + // owner: { read: true, write: true, execute: true }, + // group: { read: true, write: false, execute: true }, + // others: { read: true, write: false, execute: true }, + // uidToName: 'root', + // path: '/var', + // basename: 'var', + // extname: '' + // } // } }); }) ``` +### getStat + Read a single directory or file the [stat](http://nodejs.cn/api/fs.html#fs_class_fs_stats) info. ```js @@ -67,14 +72,7 @@ getStat('/var').then((Stats) => { // output => // Stats { // dev: 16777220, - // mode: { - // number: 16877, - // string: 'drwxr-xr-x', - // isSymbolicLink: true, - // owner: { read: true, write: true, execute: true }, - // group: { read: true, write: false, execute: true }, - // others: { read: true, write: false, execute: true } - // }, + // mode: 41453, // nlink: 26, // uid: 0, // gid: 0, @@ -91,14 +89,24 @@ getStat('/var').then((Stats) => { // mtime: 2017-09-26T05:32:50.874Z, // ctime: 2017-09-26T05:32:50.874Z, // birthtime: 2017-09-26T05:08:14.000Z, - // uidToName: 'root', - // path: '/var', - // basename: 'var', - // extname: '' + // extend: { + // number: 41453, + // isSymbolicLink: true, + // string: 'lrwxr-xr-x', + // owner: { read: true, write: true, execute: true }, + // group: { read: true, write: false, execute: true }, + // others: { read: true, write: false, execute: true }, + // uidToName: 'root', + // path: '/var', + // basename: 'var', + // extname: '' + // } // } }) ``` +### readdirAsync + Get all the file names in the directory. ```js @@ -122,6 +130,8 @@ readdirAsync('/var').then((Stats) => { }) ``` +### uidToName + ```js const { uidToName } = require('reader-stat'); @@ -148,6 +158,59 @@ uidToName(0).then((User) => { }) ``` +### chmod + +```js +const { chmod } = require('reader-stat'); +const file = path.join(__dirname, 'test.sh'); + +chmod(file, 777); +``` + +Or you can use object instead of number, see [stat-mode](https://github.com/TooTallNate/stat-mode) + +```js +chmod(file, { + owner: { + read: true, + write: true, + execute: true + }, + group: { + read: true, + write: true, + execute: true + }, + others: { + read: true, + write: true, + execute: true + } +}); +``` + +You can also write a object Simply when the same for each + +```js +chmod(file, { + read: true +}); + +// equals + +chmod(file, { + owner: { + read: true + }, + group: { + read: true + }, + others: { + read: true + } +}); +``` + ## License MIT licensed \ No newline at end of file