"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MonkeyPatch_Yaz0Decode = exports.MonkeyPatch_Yaz0Encode = void 0;
const IMonkeyPatch_1 = require("./IMonkeyPatch");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
class MonkeyPatch_Yaz0Encode extends IMonkeyPatch_1.MonkeyPatch {
    obj;
    yaz0;
    constructor(obj, yaz0) {
        super();
        this.obj = obj;
        this.yaz0 = yaz0;
    }
    patch() {
        this.original = this.yaz0["encode"];
        this.replacement = (buf) => {
            let cache_dir = "./cache";
            if (!fs_1.default.existsSync(cache_dir)) {
                fs_1.default.mkdirSync(cache_dir);
            }
            let hash = this.obj.hashBuffer(buf);
            let cached_file = path_1.default.join(cache_dir, hash);
            if (!fs_1.default.existsSync(cached_file)) {
                fs_1.default.writeFileSync(cached_file, this.original(buf));
            }
            return fs_1.default.readFileSync(cached_file);
        };
        this.obj["yaz0Encode"] = this.replacement;
    }
    unpatch() {
    }
}
exports.MonkeyPatch_Yaz0Encode = MonkeyPatch_Yaz0Encode;
class MonkeyPatch_Yaz0Decode extends IMonkeyPatch_1.MonkeyPatch {
    obj;
    yaz0;
    constructor(obj, yaz0) {
        super();
        this.obj = obj;
        this.yaz0 = yaz0;
    }
    patch() {
        this.original = this.yaz0["decode"];
        this.replacement = (buf) => {
            return this.original(buf);
        };
        this.obj["yaz0Decode"] = this.replacement;
    }
    unpatch() {
    }
}
exports.MonkeyPatch_Yaz0Decode = MonkeyPatch_Yaz0Decode;
//# sourceMappingURL=Utils.js.map