UNPKG

tardis-dev

Version:

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

48 lines 1.7 kB
import { rmSync } from 'node:fs'; import { rm } from 'node:fs/promises'; import { debug } from "./debug.js"; import { getOptions } from "./options.js"; import { sha256, optimizeFilters, doubleDigit } from "./handy.js"; export async function clearCache(exchange, filters, year, month, day) { try { const dirToRemove = getDirToRemove(exchange, filters, year, month, day); debug('clearing cache dir: %s', dirToRemove); await rm(dirToRemove, { force: true, recursive: true }); debug('cleared cache dir: %s', dirToRemove); } catch (e) { debug('clearing cache dir error: %o', e); } } export function clearCacheSync(exchange, filters, year, month, day) { try { const dirToRemove = getDirToRemove(exchange, filters, year, month, day); debug('clearing cache (sync) dir: %s', dirToRemove); rmSync(dirToRemove, { force: true, recursive: true }); debug('cleared cache(sync) dir: %s', dirToRemove); } catch (e) { debug('clearing cache (sync) dir error: %o', e); } } function getDirToRemove(exchange, filters, year, month, day) { const options = getOptions(); let dirToRemove = `${options.cacheDir}/feeds`; if (exchange !== undefined) { dirToRemove += `/${exchange}`; } if (filters !== undefined) { dirToRemove += `/${sha256(optimizeFilters(filters))}`; } if (year !== undefined) { dirToRemove += `/${year}`; } if (month !== undefined) { dirToRemove += `/${doubleDigit(month)}`; } if (day !== undefined) { dirToRemove += `/${doubleDigit(day)}`; } return dirToRemove; } //# sourceMappingURL=clearcache.js.map