文件打开的常量


以下常量旨在与 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 指示在可能的情况下以非阻塞模式打开文件的标志。
UV_FS_O_FILEMAP 设置后,将使用内存文件映射来访问文件。 此标志仅在 Windows 操作系统上可用。 在其他操作系统上,此标志被忽略。

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.
UV_FS_O_FILEMAP When set, a memory file mapping is used to access the file. This flag is available on Windows operating systems only. On other operating systems, this flag is ignored.