ninwa/libs/util.js

23 lines
576 B
JavaScript
Raw Normal View History

2022-02-15 04:33:19 +01:00
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 };
2022-02-15 04:33:19 +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 = {
getFileInfo,
2022-02-15 04:33:19 +01:00
resolvePath
}