fs.createWriteStream(path[, options])

options 可以包括一个 start 选项,允许在文件开头之后的某个位置写入数据。 如果要修改文件而不是覆盖它,则 flags 模式需要为 r+ 模式而不是默认的 w 模式。 encoding 可以是 Buffer 接受的任何一种字符编码。

如果 autoClose 设置为 true(默认行为),则在 'error''finish' 事件时文件描述符会自动关闭。 如果 autoClosefalse,则即使出现错误,也不会关闭文件描述符。 应用程序负责关闭它并确保没有文件描述符泄漏。

ReadStream 类似,如果指定了 fd,则 WriteStream 将忽略 path 参数并使用指定的文件描述符。 这意味着不会触发 'open' 事件。 fd 必须是阻塞的,非阻塞的 fd 应该传给 net.Socket

如果 options 是字符串,则它指定字符编码。

options may also include a start option to allow writing data at some position past the beginning of the file. Modifying a file rather than replacing it may require a flags mode of r+ rather than the default mode w. The encoding can be any one of those accepted by Buffer.

If autoClose is set to true (default behavior) on 'error' or 'finish' the file descriptor will be closed automatically. If autoClose is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak.

Like ReadStream, if fd is specified, WriteStream will ignore the path argument and will use the specified file descriptor. This means that no 'open' event will be emitted. fd should be blocking; non-blocking fds should be passed to net.Socket.

If options is a string, then it specifies the encoding.