| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8dbf334 commit c9cf41d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3130,6 +3130,9 @@ from the current position. | |||
| 3130 | 3130 | The callback will be given three arguments: `err`, `bytesRead`, and | |
| 3131 | 3131 | `buffers`. `bytesRead` is how many bytes were read from the file. | |
| 3132 | 3132 | ||
| 3133 | + If this method is invoked as its [`util.promisify()`][]ed version, it returns | ||
| 3134 | + a `Promise` for an `Object` with `bytesRead` and `buffers` properties. | ||
| 3135 | + | ||
| 3133 | 3136 | ## `fs.readvSync(fd, buffers[, position])` | |
| 3134 | 3137 | <!-- YAML | |
| 3135 | 3138 | added: v12.17.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -584,6 +584,9 @@ function readv(fd, buffers, position, callback) { | |||
| 584 | 584 | return binding.readBuffers(fd, buffers, position, req); | |
| 585 | 585 | } | |
| 586 | 586 | ||
| 587 | + ObjectDefineProperty(readv, internalUtil.customPromisifyArgs, | ||
| 588 | + { value: ['bytesRead', 'buffers'], enumerable: false }); | ||
| 589 | + | ||
| 587 | 590 | function readvSync(fd, buffers, position) { | |
| 588 | 591 | validateInt32(fd, 'fd', 0); | |
| 589 | 592 | validateBufferArray(buffers); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const fixtures = require('../common/fixtures'); | ||
| 5 | + const fs = require('fs'); | ||
| 6 | + const readv = require('util').promisify(fs.readv); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const filepath = fixtures.path('x.txt'); | ||
| 9 | + const fd = fs.openSync(filepath, 'r'); | ||
| 10 | + | ||
| 11 | + const expected = [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()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments