UNPKG

bowling-analysis-system

Version:

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

55 lines (51 loc) 1.24 kB
/** * @module FileReader * @description Reads files from the filesystem */ const fs = require('fs'); const path = require('path'); /** * @class FileReader * @description Reads files from the filesystem */ class FileReader { /** * Create a new file reader * @param {Object} options - Reader options */ constructor(options = {}) { this.options = { encoding: 'utf8', ...options }; } /** * Read a file * @param {string} filePath - Path to the file * @returns {Promise<string>} File contents */ async readFile(filePath) { try { return await fs.promises.readFile(filePath, this.options.encoding); } catch (error) { console.error(`Error reading file ${filePath}: ${error.message}`); return null; } } /** * Read a JSON file * @param {string} filePath - Path to the JSON file * @returns {Promise<Object>} Parsed JSON object */ async readJsonFile(filePath) { try { const data = await this.readFile(filePath); if (!data) return null; return JSON.parse(data); } catch (error) { console.error(`Error parsing JSON file ${filePath}: ${error.message}`); return null; } } } module.exports = FileReader;