阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js fs filehandle.write

      Node.js

      filehandle.write(buffer, offset, length, position)

      新增于: v10.0.0

      • buffer < Buffer> |
      • offset < integer>
      • length < integer>
      • position < integer>
      • Returns:

      Write buffer to the file.

      The Promise is resolved with an object containing a bytesWritten property identifying the number of bytes written, and a buffer property containing a reference to the buffer written.

      offset determines the part of the buffer to be written, and length is an integer specifying the number of bytes to write.

      position refers to the offset from the beginning of the file where this data should be written. If typeof position !== ‘number’, the data will be written at the current position. See pwrite(2).

      It is unsafe to use filehandle.write() multiple times on the same file without waiting for the Promise to be resolved (or rejected). For this scenario, fs.createWriteStream() is strongly recommended.

      On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.

      filehandle.write(string[, position[, encoding]])

      新增于: v10.0.0

      • string < string>
      • position < integer>
      • encoding < string> Default: ‘utf8’
      • Returns:

      Write string to the file. If string is not a string, then the value will be coerced to one.

      The Promise is resolved with an object containing a bytesWritten property identifying the number of bytes written, and a buffer property containing a reference to the string written.

      position refers to the offset from the beginning of the file where this data should be written. If the type of position is not a number the data will be written at the current position. See pwrite(2).

      encoding is the expected string encoding.

      It is unsafe to use filehandle.write() multiple times on the same file without waiting for the Promise to be resolved (or rejected). For this scenario, fs.createWriteStream() is strongly recommended.

      On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.


      更多内容请参考:Node.js fs 文件系统,或者通过 点击对应菜单 进行查看;


      目录
      目录