mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
lib: fix readFile flag option typo
PR-URL: https://github.com/nodejs/node/pull/35292 Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
1 parent
9288f9d74b
commit
cd0b1365ae
2 files changed
+52
-1
No files matched your search
@@ -322,7 +322,7 @@ function readFile(path, options, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
const flagsNumber = stringToFlags(options.flags);
|
||||
const flagsNumber = stringToFlags(options.flag);
|
||||
path = getValidatedPath(path);
|
||||
|
||||
const req = new FSReqCallback();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
// Test of fs.readFile with different flags.
|
||||
const common = require('../common');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
|
||||
tmpdir.refresh();
|
||||
|
||||
{
|
||||
const emptyFile = path.join(tmpdir.path, 'empty.txt');
|
||||
fs.closeSync(fs.openSync(emptyFile, 'w'));
|
||||
|
||||
fs.readFile(
|
||||
emptyFile,
|
||||
// With `a+` the file is created if it does not exist
|
||||
{ encoding: 'utf8', flag: 'a+' },
|
||||
common.mustCall((err, data) => { assert.strictEqual(data, ''); })
|
||||
);
|
||||
|
||||
fs.readFile(
|
||||
emptyFile,
|
||||
// Like `a+` but fails if the path exists.
|
||||
{ encoding: 'utf8', flag: 'ax+' },
|
||||
common.mustCall((err, data) => { assert.strictEqual(err.code, 'EEXIST'); })
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const willBeCreated = path.join(tmpdir.path, 'will-be-created');
|
||||
|
||||
fs.readFile(
|
||||
willBeCreated,
|
||||
// With `a+` the file is created if it does not exist
|
||||
{ encoding: 'utf8', flag: 'a+' },
|
||||
common.mustCall((err, data) => { assert.strictEqual(data, ''); })
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const willNotBeCreated = path.join(tmpdir.path, 'will-not-be-created');
|
||||
|
||||
fs.readFile(
|
||||
willNotBeCreated,
|
||||
// Default flag is `r`. An exception occurs if the file does not exist.
|
||||
{ encoding: 'utf8' },
|
||||
common.mustCall((err, data) => { assert.strictEqual(err.code, 'ENOENT'); })
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user