этот режим указывает некоторую информацию о файле, например:
- Разрешения (для пользователя, группы и других)
- тип файла
Комунемного отфильтруйте эти данные, в ОС определены некоторые маски для извлечения необходимой нам информации.Эти маски:
* For filter permissions (user, group and other)
The following mask values are defined for the file mode component of the st_mode field:
S_ISUID 04000 set-user-ID bit
S_ISGID 02000 set-group-ID bit (see below)
S_ISVTX 01000 sticky bit (see below)
S_IRWXU 00700 owner has read, write, and execute permission
S_IRUSR 00400 owner has read permission
S_IWUSR 00200 owner has write permission
S_IXUSR 00100 owner has execute permission
S_IRWXG 00070 group has read, write, and execute permission
S_IRGRP 00040 group has read permission
S_IWGRP 00020 group has write permission
S_IXGRP 00010 group has execute permission
S_IRWXO 00007 others (not in group) have read, write, and
execute permission
S_IROTH 00004 others have read permission
S_IWOTH 00002 others have write permission
S_IXOTH 00001 others have execute permission
* For detect type of file
The following mask values are defined for the file type:
S_IFMT 0170000 bit mask for the file type bit field
S_IFSOCK 0140000 socket
S_IFLNK 0120000 symbolic link
S_IFREG 0100000 regular file
S_IFBLK 0060000 block device
S_IFDIR 0040000 directory
S_IFCHR 0020000 character device
S_IFIFO 0010000 FIFO
Сценарий 1: файл имеет доступ для чтения (для всех)
const fs = require('fs');
const mode = fs.statSync('./yourfile.txt').mode;
if (mode & (fs.constants.S_IRUSR | fs.constants.S_IRGRP | fs.constants.S_IROTH)) {
console.log('file has read permissions');
}
Сценарий 2: символьная ссылка
if (mode & fs.constants.S_IFLNK) {
console.log("It's a symbolic link");
} else {
console.log("It's not a symbolic link");
}
Надеюсь, это поможет вам понять, как работает ОС (Unix-системы).Дополнительная информация: http://man7.org/linux/man-pages/man7/inode.7.html