ethers.js/packages/testcases/lib/browser-disk-utils.js

44 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2020-11-16 23:07:24 -05:00
'use strict';
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
2021-03-07 18:24:04 -05:00
exports.loadData = exports.loadTests = exports.saveTests = void 0;
2020-11-16 23:07:24 -05:00
var tiny_inflate_1 = __importDefault(require("tiny-inflate"));
var ethers_1 = require("ethers");
// This file is populated by the rollup-pre-alias.config.js
var browser_data_json_1 = __importDefault(require("./browser-data.json"));
function saveTests(tag, data) {
throw new Error("browser does not support writing testcases");
}
exports.saveTests = saveTests;
var Cache = {};
function loadTests(tag) {
var filename = 'testcases/' + tag + ".json.gz";
if (Cache[filename] == null) {
console.log("Loading Test Case: " + filename);
try {
var fileData = browser_data_json_1.default[filename];
var comps = fileData.split(",");
var size = parseInt(comps[0]), compressedData = ethers_1.ethers.utils.base64.decode(comps[1]);
var uncompressedData = new Uint8Array(size);
tiny_inflate_1.default(compressedData, uncompressedData);
Cache[filename] = JSON.parse(ethers_1.ethers.utils.toUtf8String(uncompressedData));
}
catch (error) {
console.log("ERROR", error);
throw error;
}
}
return Cache[filename];
}
exports.loadTests = loadTests;
function loadData(filename) {
// Strip any leading relative paths (e.g. "./foo" => "foo")
filename = filename.replace(/^[^a-z0-9_]/i, "");
console.log("Loading Data File: " + filename);
//filename = path.join(filename);
return ethers_1.ethers.utils.base64.decode(browser_data_json_1.default[filename]);
}
exports.loadData = loadData;
//# sourceMappingURL=browser-disk-utils.js.map