-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchmod.js
More file actions
28 lines (26 loc) · 690 Bytes
/
Copy pathchmod.js
File metadata and controls
28 lines (26 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import fs from 'node:fs';
/**
* Changing file permissions
* @param {import('fs').PathLike} path
* @param {string|number} mode
* @param {(err: Error | null) => void} callback
*/
export default function chmod(path, mode, callback) {
// 检查参数
if (typeof path !== 'string') {
throw new TypeError('path must be a string');
}
if (typeof mode !== 'string' && typeof mode !== 'number') {
throw new TypeError('mode must be a string or number');
}
if (typeof callback !== 'function') {
throw new TypeError('callback must be a function');
}
fs.chmod(path, mode, (err) => {
if (err) {
callback(err);
return;
}
callback(null);
});
}