This repository has been archived on 2025-12-24. You can view files and clone it, but cannot push or open issues or pull requests.
site-template/packages/imagetoolsOSR/plugin/utils/cache.js
2025-03-07 14:59:06 +01:00

18 lines
413 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;
}