| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cb8b9ec commit b280c86
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3191,6 +3191,9 @@ from the current position. | |||
| 3191 | 3191 | The callback will be given three arguments: `err`, `bytesRead`, and | |
| 3192 | 3192 | `buffers`. `bytesRead` is how many bytes were read from the file. | |
| 3193 | 3193 | ||
| 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 | + | ||
| 3194 | 3197 | ## `fs.readvSync(fd, buffers[, position])` | |
| 3195 | 3198 | <!-- YAML | |
| 3196 | 3199 | added: v14.0.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -597,6 +597,9 @@ function readv(fd, buffers, position, callback) { | |||
| 597 | 597 | return binding.readBuffers(fd, buffers, position, req); | |
| 598 | 598 | } | |
| 599 | 599 | ||
| 600 | + ObjectDefineProperty(readv, internalUtil.customPromisifyArgs, | ||
| 601 | + { value: ['bytesRead', 'buffers'], enumerable: false }); | ||
| 602 | + | ||
| 600 | 603 | function readvSync(fd, buffers, position) { | |
| 601 | 604 | validateInt32(fd, 'fd', 0); | |
| 602 | 605 | 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