Continue ESM transform

This commit is contained in:
be5invis 2022-07-16 20:18:52 -07:00
parent b8205a63aa
commit 36835216f5
44 changed files with 1939 additions and 502 deletions

View file

@ -1,5 +1,6 @@
import fs from "fs";
import zlib from "zlib";
import { encode, decode } from "@msgpack/msgpack";
const Edition = 20;
@ -75,8 +76,13 @@ class Cache {
export const load = async function (path, version, freshAgeKey) {
let cache = new Cache(freshAgeKey);
if (path && fs.existsSync(path)) {
const buf = zlib.gunzipSync(await fs.promises.readFile(path));
cache.loadRep(version, decode(buf));
try {
const buf = zlib.gunzipSync(await fs.promises.readFile(path));
cache.loadRep(version, decode(buf));
} catch (e) {
console.error("Error loading cache. Treat as empty.");
console.error(e);
}
}
return cache;
};