@abextm/cache2
Version:
Utilities for reading OSRS "caches"
27 lines (26 loc) • 872 B
JavaScript
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { DiskCacheProvider } from "../DiskCache.js";
import { FlatCacheProvider } from "../FlatCache.js";
export class NodeFSFileProvider {
path;
constructor(path) {
this.path = path;
}
getFile(name) {
return fs.readFile(path.join(this.path, name));
}
exists(name) {
return fs.access(path.join(this.path, name)).then(_ => true, _ => false);
}
}
export async function loadCache(filePath) {
let fileProvider = new NodeFSFileProvider(filePath);
if (await fileProvider.exists("main_file_cache.dat2")) {
return new DiskCacheProvider(fileProvider);
}
if (await fileProvider.exists("0.flatcache")) {
return new FlatCacheProvider(fileProvider);
}
throw new Error(`Path "${filePath}" does not contain a cache`);
}