UNPKG

redis-smq-common

Version:

RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.

56 lines 2.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.doesPathExist = doesPathExist; exports.ensureDirectoryExists = ensureDirectoryExists; exports.downloadFile = downloadFile; const axios_1 = __importDefault(require("axios")); const fs_1 = __importDefault(require("fs")); const promises_1 = require("node:fs/promises"); function doesPathExist(filePath) { return __awaiter(this, void 0, void 0, function* () { try { yield (0, promises_1.access)(filePath, promises_1.constants.F_OK); return true; } catch (_a) { return false; } }); } function ensureDirectoryExists(dirPath) { return __awaiter(this, void 0, void 0, function* () { try { yield (0, promises_1.access)(dirPath, promises_1.constants.F_OK); } catch (_a) { yield (0, promises_1.mkdir)(dirPath, { recursive: true }); } }); } function downloadFile(url, savePath) { return __awaiter(this, void 0, void 0, function* () { const response = yield (0, axios_1.default)({ url, responseType: 'stream', }); const writer = fs_1.default.createWriteStream(savePath); response.data.pipe(writer); return new Promise((resolve, reject) => { writer.on('finish', resolve); writer.on('error', reject); }); }); } //# sourceMappingURL=filesystem.js.map