1.0.6 • Published 5 years ago
fs-chmod v1.0.6
fs-chmod
A drop-in replacement of fs.chmod
with +x
support.
- supports finer-grained symbolic modes, such as
+x
,ug+rw
, and etc. - supports mode object to make the mode better described.
Install
$ npm i fs-chmod
Usage
const {
chmod,
chmodSync,
parse
} = require('fs-chmod')
chmod('/path/to/file.js', '+x').then(() => {
console.log('done')
})
chmodSync.sync('/path/to/file.js', 'a+x')
chmod(path, mode): Promise
chmod(path, mode, callback): void
chmodSync(path, mode): void
- path
string | Buffer | URL
the same as vanillafs.chmod
- mode
integer | Mode | string
- callback
Function(error?)
Changes the permissions of a file.
parse(str): Mode
- str
string
Symbolic notation string of file system permissions
Parses the symbolic notation string, such as +x
, ug+rwx
into an object of the interface Mode
(see below)
const mode = parse('u+x')
console.log(mode.owner.execute) // true
console.log(mode.owner.read) // false
console.log(mode.group) // undefined
mode
mode integer
The same as the the second parameter of vanilla fs.chmod
.
PAY ATTENTION that mode
should be an octal number.
chmodSync('/path/to/file', 0o777) // ✅ Correct~
chmodSync('/path/to/file', 777) // ❌ WRONG!
mode object<Mode>
interface Permission {
read?: boolean
write?: boolean
execute?: boolean
}
interface Mode {
owner?: Permission
group?: Permission
others?: Permission
setuid?: boolean
setgid?: boolean
sticky?: boolean
}
For details, see symbolic modes
# bash
chmod ug+rst /path/to/file
is equivalent to
chmodSync('path/to/file', 'ug+rst')
// or
chmodSync('path/to/file', {
owner: {
read: true
},
group: {
read: true
},
setuid: true,
setgid: true,
sticky: true
})
mode string
[references][operator][modes]
- Supported references:
u
,g
,o
,a
- Supported operators:
+
,=
,-
- Supported modes:
r
,w
,x
s
: setuid/setgidt
: sticky