ninwa/libs/util.js

23 lines
No EOL
576 B
JavaScript

const realpath = require('fs/promises').realpath;
const stat = require('fs/promises').stat;
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 };
}
async function resolvePath(file) {
if (file === undefined) {
throw new Error('can not resolve a path to an undefined file');
}
return realpath(file);
}
module.exports = {
getFileInfo,
resolvePath
}