-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../../test/common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const paths = [ | ||
__filename, | ||
tmpdir.resolve(`.non-existing-file-${process.pid}`), | ||
]; | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
}); | ||
|
||
function main({ n }) { | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
for (let j = 0; j < paths.length; j++) { | ||
fs.existsSync(paths[j]); | ||
} | ||
} | ||
bench.end(n); | ||
} |
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
'use strict'; | ||
|
||
const pathModule = require('path'); | ||
const { handleErrorFromBinding, getValidatedPath, stringToFlags } = require('internal/fs/utils'); | ||
|
||
const syncBinding = internalBinding('fs_sync'); | ||
|
||
/** | ||
* @param {string} path | ||
* @param {number} flag | ||
* @return {string} | ||
*/ | ||
function readFileUtf8(path, flag) { | ||
path = pathModule.toNamespacedPath(getValidatedPath(path)); | ||
const response = syncBinding.readFileUtf8(path, stringToFlags(flag)); | ||
|
||
if (typeof response === 'string') { | ||
return response; | ||
} | ||
|
||
const { 0: errno, 1: syscall } = response; | ||
handleErrorFromBinding({ errno, syscall, path }); | ||
} | ||
|
||
function exists(path) { | ||
try { | ||
path = getValidatedPath(path); | ||
} catch { | ||
return false; | ||
} | ||
|
||
return syncBinding.exists(pathModule.toNamespacedPath(path)); | ||
} | ||
|
||
module.exports = { | ||
readFileUtf8, | ||
exists, | ||
}; |
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