-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: remove fs.read's string interface #9683
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const filepath = path.join(common.fixturesDir, 'x.txt'); | ||
const fd = fs.openSync(filepath, 'r'); | ||
const expected = 'xyz\n'; | ||
|
||
// Error must be thrown with string | ||
assert.throws(() => { | ||
fs.read(fd, | ||
expected.length, | ||
0, | ||
'utf-8', | ||
() => {}); | ||
}, /Second argument needs to be a buffer/); | ||
|
||
assert.throws(() => { | ||
fs.readSync(fd, expected.length, 0, 'utf-8'); | ||
}, /Second argument needs to be a buffer/); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,18 @@ | |
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const Buffer = require('buffer').Buffer; | ||
const fs = require('fs'); | ||
const filepath = path.join(common.fixturesDir, 'x.txt'); | ||
const fd = fs.openSync(filepath, 'r'); | ||
const expected = ''; | ||
const bufferAsync = Buffer.alloc(0); | ||
const bufferSync = Buffer.alloc(0); | ||
|
||
fs.read(fd, 0, 0, 'utf-8', common.mustCall(function(err, str, bytesRead) { | ||
assert.ok(!err); | ||
assert.equal(str, expected); | ||
fs.read(fd, bufferAsync, 0, 0, 0, common.mustCall(function(err, bytesRead) { | ||
assert.equal(bytesRead, 0); | ||
assert.deepStrictEqual(bufferAsync, Buffer.alloc(0)); | ||
})); | ||
|
||
const r = fs.readSync(fd, 0, 0, 'utf-8'); | ||
assert.equal(r[0], expected); | ||
assert.equal(r[1], 0); | ||
const r = fs.readSync(fd, bufferSync, 0, 0, 0); | ||
assert.deepStrictEqual(bufferSync, Buffer.alloc(0)); | ||
assert.equal(r, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to keep test files unrelated to this PR unmodified, since I'm not familiar with their finer details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, this is not the actual "expected", right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your suggestion?