UNPKG

@ohd-tools/utils

Version:
39 lines (38 loc) 1.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable @typescript-eslint/no-explicit-any */ const path_1 = __importDefault(require("path")); const ftp_tail_1 = require("../ftp-tail"); class TailLogReader { options; reader; queueLine; constructor(queueLine, options = {}) { for (const option of ['sftp', 'logDir']) if (!(option in options)) throw new Error(`${option} must be specified.`); this.options = options; if (typeof queueLine !== 'function') throw new Error('queueLine argument must be specified and be a function.'); } async setup() { this.reader = new ftp_tail_1.SFTPTail({ sftp: this.options.sftp, fetchInterval: this.options.fetchInterval ?? 0, maxTempFileSize: this.options.maxTempFileSize ?? 5 * 1000 * 1000, // 5 MB }); this.reader.on('line', this.queueLine); } async watch() { await this.reader.watch(path_1.default .join(this.options.logDir, this.options.filename) .replace(/\\/g, '/')); } async unwatch() { await this.reader.unwatch(); } } exports.default = TailLogReader;