UNPKG

bowling-analysis-system

Version:

A comprehensive system for analyzing bowling techniques using video processing and metrics calculation

67 lines (58 loc) 1.82 kB
/** * File Saver Processor * * Saves files to the filesystem * @module processors/FileSaverProcessor */ const { BaseProcessor } = require('../core/BaseProcessor'); const { defaultFileService } = require('../utils/FileService'); /** * @class FileSaverProcessor * @description Processor for saving data to the filesystem * @extends BaseProcessor */ class FileSaverProcessor extends BaseProcessor { /** * Create a new file saver processor * @param {Object} config - Processor configuration */ constructor(config = {}) { super('fileSaver', config); this.fileService = defaultFileService; } /** * Process input by saving it to a file * @param {*} input - Input data to save * @param {Object} context - Processing context * @returns {Promise<Object>} Result with saved file path * @protected */ async _process(input, context) { const filePath = this.config.path || context.outputPath; if (!filePath) { throw new Error('No output file path specified'); } try { // Create directory if needed if (this.config.createDirectory) { await this.fileService.ensureDir(this.fileService.dirname(filePath)); } // Determine format const format = this.config.format || 'json'; // Save file based on format if (format === 'json') { await this.fileService.writeJsonFile(filePath, input); } else { await this.fileService.writeFile(filePath, input); } return { path: filePath, saved: true, data: input }; } catch (error) { throw new Error(`Failed to save file ${filePath}: ${error.message}`); } } } module.exports = FileSaverProcessor;