forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: make parameters optional for readSync
This makes the offset, length and position parameters optional by passing in an options object. PR-URL: nodejs#32460 Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
1 parent
4259bbb
commit c4e74f0
Showing
3 changed files
with
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
const filepath = fixtures.path('x.txt'); | ||
const fd = fs.openSync(filepath, 'r'); | ||
|
||
const expected = Buffer.from('xyz\n'); | ||
|
||
function runTest(defaultBuffer, options) { | ||
const result = fs.readSync(fd, defaultBuffer, options); | ||
assert.strictEqual(result, expected.length); | ||
assert.deepStrictEqual(defaultBuffer, expected); | ||
} | ||
|
||
// Test passing in an empty options object | ||
runTest(Buffer.allocUnsafe(expected.length), { position: 0 }); | ||
|
||
// Test not passing in any options object | ||
runTest(Buffer.allocUnsafe(expected.length)); | ||
|
||
// Test passing in options | ||
runTest(Buffer.allocUnsafe(expected.length), { offset: 0, | ||
length: expected.length, | ||
position: 0 }); |