文件打开的常量


以下常量适用于 fs.open()

常量 说明
O_RDONLY 表明打开文件用于只读访问。
O_WRONLY 表明打开文件用于只写访问。
O_RDWR 表明打开文件用于读写访问。
O_CREAT 表明如果文件尚不存在则创建该文件。
O_EXCL 表明如果设置了 O_CREAT 标志且文件已存在,则打开文件应该失败。
O_NOCTTY 表明如果路径是终端设备,则打开该路径不应该造成该终端变成进程的控制终端(如果进程还没有终端)。
O_TRUNC 表明如果文件存在且是常规文件、并且文件成功打开以进行写入访问,则其长度应截断为零。
O_APPEND 表明数据将追加到文件末尾。
O_DIRECTORY 表明如果路径不是目录,则打开应该失败。
O_NOATIME 表明文件系统的读取访问将不再导致与文件相关联的 atime 信息的更新。 仅在 Linux 操作系统上可用。
O_NOFOLLOW 表明如果路径是符号链接,则打开应该失败。
O_SYNC 表明文件是为同步 I/O 打开的,写入操作将等待文件的完整性。
O_DSYNC 表明文件是为同步 I/O 打开的,写入操作将等待数据的完整性
O_SYMLINK 表明打开符号链接自身,而不是它指向的资源。
O_DIRECT 表明将尝试最小化文件 I/O 的缓存效果。
O_NONBLOCK 表明在可能的情况下以非阻塞模式打开文件。

The following constants are meant for use with fs.open().

Constant Description
O_RDONLY Flag indicating to open a file for read-only access.
O_WRONLY Flag indicating to open a file for write-only access.
O_RDWR Flag indicating to open a file for read-write access.
O_CREAT Flag indicating to create the file if it does not already exist.
O_EXCL Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists.
O_NOCTTY Flag indicating that if path identifies a terminal device, opening the path shall not cause that terminal to become the controlling terminal for the process (if the process does not already have one).
O_TRUNC Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero.
O_APPEND Flag indicating that data will be appended to the end of the file.
O_DIRECTORY Flag indicating that the open should fail if the path is not a directory.
O_NOATIME Flag indicating reading accesses to the file system will no longer result in an update to the atime information associated with the file. This flag is available on Linux operating systems only.
O_NOFOLLOW Flag indicating that the open should fail if the path is a symbolic link.
O_SYNC Flag indicating that the file is opened for synchronized I/O with write operations waiting for file integrity.
O_DSYNC Flag indicating that the file is opened for synchronized I/O with write operations waiting for data integrity.
O_SYMLINK Flag indicating to open the symbolic link itself rather than the resource it is pointing to.
O_DIRECT When set, an attempt will be made to minimize caching effects of file I/O.
O_NONBLOCK Flag indicating to open the file in nonblocking mode when possible.