import { writeFile, unlink } from 'fs/promises'; import { join } from 'path'; export async function saveFile(uploadDir: string, storedName: string, data: Buffer): Promise { await writeFile(join(uploadDir, storedName), data); return storedName; } export function getFilePath(uploadDir: string, storedName: string): string { return join(uploadDir, storedName); } export async function deleteStoredFile(uploadDir: string, storedName: string): Promise { try { await unlink(join(uploadDir, storedName)); } catch (err: unknown) { if ((err as NodeJS.ErrnoException).code !== 'ENOENT') { throw err; } } }