UNPKG

tardis-dev

Version:

Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js

52 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clearCacheSync = exports.clearCache = void 0; const fs_extra_1 = require("fs-extra"); const debug_1 = require("./debug"); const options_1 = require("./options"); const handy_1 = require("./handy"); async function clearCache(exchange, filters, year, month, day) { try { const dirToRemove = getDirToRemove(exchange, filters, year, month, day); (0, debug_1.debug)('clearing cache dir: %s', dirToRemove); await (0, fs_extra_1.remove)(dirToRemove); (0, debug_1.debug)('cleared cache dir: %s', dirToRemove); } catch (e) { (0, debug_1.debug)('clearing cache dir error: %o', e); } } exports.clearCache = clearCache; function clearCacheSync(exchange, filters, year, month, day) { try { const dirToRemove = getDirToRemove(exchange, filters, year, month, day); (0, debug_1.debug)('clearing cache (sync) dir: %s', dirToRemove); (0, fs_extra_1.removeSync)(dirToRemove); (0, debug_1.debug)('cleared cache(sync) dir: %s', dirToRemove); } catch (e) { (0, debug_1.debug)('clearing cache (sync) dir error: %o', e); } } exports.clearCacheSync = clearCacheSync; function getDirToRemove(exchange, filters, year, month, day) { const options = (0, options_1.getOptions)(); let dirToRemove = `${options.cacheDir}/feeds`; if (exchange !== undefined) { dirToRemove += `/${exchange}`; } if (filters !== undefined) { dirToRemove += `/${(0, handy_1.sha256)((0, handy_1.optimizeFilters)(filters))}`; } if (year !== undefined) { dirToRemove += `/${year}`; } if (month !== undefined) { dirToRemove += `/${(0, handy_1.doubleDigit)(month)}`; } if (day !== undefined) { dirToRemove += `/${(0, handy_1.doubleDigit)(day)}`; } return dirToRemove; } //# sourceMappingURL=clearcache.js.map