Skip to content

Commit

Permalink
Update document.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 27, 2018
1 parent 86f6e6e commit beb36e2
Showing 1 changed file with 87 additions and 24 deletions.
111 changes: 87 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ npm install reader-stat --save

## Usage

### readdir

```js
const { readdir } = require('reader-stat');

Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -122,6 +130,8 @@ readdirAsync('/var').then((Stats) => {
})
```

### uidToName

```js
const { uidToName } = require('reader-stat');

Expand All @@ -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

0 comments on commit beb36e2

Please sign in to comment.