Skip to content

Commit b280c86

Browse files
lholmquistcodebytere
authored andcommitted
fs: support util.promisify for fs.readv
PR-URL: #33590 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent cb8b9ec commit b280c86

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎doc/api/fs.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,6 +3191,9 @@ from the current position.
31913191
The callback will be given three arguments: `err`, `bytesRead`, and
31923192
`buffers`. `bytesRead` is how many bytes were read from the file.
31933193

3194+
If this method is invoked as its [`util.promisify()`][]ed version, it returns
3195+
a `Promise` for an `Object` with `bytesRead` and `buffers` properties.
3196+
31943197
## `fs.readvSync(fd, buffers[, position])`
31953198
<!-- YAML
31963199
added: v14.0.0

‎lib/fs.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ function readv(fd, buffers, position, callback) {
597597
returnbinding.readBuffers(fd,buffers,position,req);
598598
}
599599

600+
ObjectDefineProperty(readv,internalUtil.customPromisifyArgs,
601+
{value: ['bytesRead','buffers'],enumerable: false});
602+
600603
functionreadvSync(fd,buffers,position){
601604
validateInt32(fd,'fd',0);
602605
validateBufferArray(buffers);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constfixtures=require('../common/fixtures');
5+
constfs=require('fs');
6+
constreadv=require('util').promisify(fs.readv);
7+
constassert=require('assert');
8+
constfilepath=fixtures.path('x.txt');
9+
constfd=fs.openSync(filepath,'r');
10+
11+
constexpected=[Buffer.from('xyz\n')];
12+
13+
readv(fd,expected)
14+
.then(function({ bytesRead, buffers }){
15+
assert.deepStrictEqual(bytesRead,expected[0].length);
16+
assert.deepStrictEqual(buffers,expected);
17+
})
18+
.then(common.mustCall());

0 commit comments

Comments
 (0)