polymech-astro/packages/imagetools_3/plugin/utils/cache.js
2025-12-24 11:47:18 +01:00

14 lines
409 B
JavaScript

// @ts-check
import fs from "node:fs";
import { fsCachePath } from "../../utils/runtimeChecks.js";
export async function getCachedBuffer(hash, image) {
const cacheFilePath = fsCachePath + hash;
if (fs.existsSync(cacheFilePath)) {
return fs.promises.readFile(cacheFilePath);
}
const buffer = await image.clone().toBuffer();
await fs.promises.writeFile(cacheFilePath, buffer);
return buffer;
}