2022-02-15 04:33:19 +01:00
|
|
|
const realpath = require('fs/promises').realpath;
|
|
|
|
const stat = require('fs/promises').stat;
|
|
|
|
|
2022-03-10 12:29:41 +01:00
|
|
|
async function getFileInfo(file) {
|
|
|
|
if (file === undefined) {
|
|
|
|
throw new Error('can not check the existence of an undefined file');
|
|
|
|
}
|
|
|
|
const path = await resolvePath(file);
|
|
|
|
const stats = await stat(path);
|
|
|
|
return { path, stats };
|
2022-02-15 04:33:19 +01:00
|
|
|
}
|
|
|
|
|
2022-03-10 12:29:41 +01:00
|
|
|
async function resolvePath(file) {
|
|
|
|
if (file === undefined) {
|
|
|
|
throw new Error('can not resolve a path to an undefined file');
|
|
|
|
}
|
|
|
|
return realpath(file);
|
2022-02-15 04:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2022-03-10 12:29:41 +01:00
|
|
|
getFileInfo,
|
2022-02-15 04:33:19 +01:00
|
|
|
resolvePath
|
|
|
|
}
|