-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#25925 added fs.writev() and fs.writevSync(), but did not include a Promises based equivalent. This commit adds the missing method. Refs: #25925 PR-URL: #29186 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs').promises; | ||
const tmpdir = require('../common/tmpdir'); | ||
const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف'; | ||
let cnt = 0; | ||
|
||
function getFileName() { | ||
return path.join(tmpdir.path, `writev_promises_${++cnt}.txt`); | ||
} | ||
|
||
tmpdir.refresh(); | ||
|
||
(async () => { | ||
{ | ||
const filename = getFileName(); | ||
const handle = await fs.open(filename, 'w'); | ||
const buffer = Buffer.from(expected); | ||
const bufferArr = [buffer, buffer]; | ||
const expectedLength = bufferArr.length * buffer.byteLength; | ||
let { bytesWritten, buffers } = await handle.writev([Buffer.from('')], | ||
null); | ||
assert.deepStrictEqual(bytesWritten, 0); | ||
assert.deepStrictEqual(buffers, [Buffer.from('')]); | ||
({ bytesWritten, buffers } = await handle.writev(bufferArr, null)); | ||
assert.deepStrictEqual(bytesWritten, expectedLength); | ||
assert.deepStrictEqual(buffers, bufferArr); | ||
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename))); | ||
handle.close(); | ||
} | ||
|
||
// fs.promises.writev() with an array of buffers without position. | ||
{ | ||
const filename = getFileName(); | ||
const handle = await fs.open(filename, 'w'); | ||
const buffer = Buffer.from(expected); | ||
const bufferArr = [buffer, buffer, buffer]; | ||
const expectedLength = bufferArr.length * buffer.byteLength; | ||
let { bytesWritten, buffers } = await handle.writev([Buffer.from('')]); | ||
assert.deepStrictEqual(bytesWritten, 0); | ||
assert.deepStrictEqual(buffers, [Buffer.from('')]); | ||
({ bytesWritten, buffers } = await handle.writev(bufferArr)); | ||
assert.deepStrictEqual(bytesWritten, expectedLength); | ||
assert.deepStrictEqual(buffers, bufferArr); | ||
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename))); | ||
handle.close(); | ||
} | ||
})(); |