From 3273d0e9514da750405cc2e3662d72dcbb489380 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 17 Aug 2019 14:56:13 -0400 Subject: [PATCH 1/2] fs: add writev() promises version https://github.com/nodejs/node/pull/25925 added fs.writev() and fs.writevSync(), but did not include a Promises based equivalent. This commit adds the missing method. Refs: https://github.com/nodejs/node/pull/25925 PR-URL: https://github.com/nodejs/node/pull/29186 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: James M Snell --- doc/api/fs.md | 26 ++++++++++++ lib/internal/fs/promises.js | 17 ++++++++ lib/internal/fs/utils.js | 14 +++++++ test/parallel/test-fs-writev-promises.js | 51 ++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 test/parallel/test-fs-writev-promises.js diff --git a/doc/api/fs.md b/doc/api/fs.md index d71f8afd82b878..58b17c3b21902a 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -4274,6 +4274,32 @@ If one or more `filehandle.write()` calls are made on a file handle and then a current position till the end of the file. It doesn't always write from the beginning of the file. +#### filehandle.writev(buffers[, position]) + + +* `buffers` {ArrayBufferView[]} +* `position` {integer} +* Returns: {Promise} + +Write an array of `ArrayBufferView`s to the file. + +The `Promise` is resolved with an object containing a `bytesWritten` property +identifying the number of bytes written, and a `buffers` property containing +a reference to the `buffers` input. + +`position` is 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. + +It is unsafe to call `writev()` multiple times on the same file without waiting +for the previous operation to complete. + +On Linux, positional writes don't 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. + ### fsPromises.access(path[, mode])