Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
26 lines
692 B
Plaintext
26 lines
692 B
Plaintext
import { fileTypeFromFile } from 'file-type';
|
|
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
const mimeTypeEstimate = {
|
|
svg: 'image/svg+xml'
|
|
};
|
|
export const getFileByPath = async (filePath)=>{
|
|
if (typeof filePath !== 'string') {
|
|
return undefined;
|
|
}
|
|
const name = path.basename(filePath);
|
|
const ext = path.extname(filePath).slice(1);
|
|
const [data, stat, type] = await Promise.all([
|
|
fs.readFile(filePath),
|
|
fs.stat(filePath),
|
|
fileTypeFromFile(filePath)
|
|
]);
|
|
return {
|
|
name,
|
|
data,
|
|
mimetype: type?.mime || mimeTypeEstimate[ext],
|
|
size: stat.size
|
|
};
|
|
};
|
|
|
|
//# sourceMappingURL=getFileByPath.js.map |