const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
/**
* Mirrors data from a source file to a destination file.
*
* @param {object} config - Configuration object containing source and destination file paths.
* @param {string} config.source - Path to the source file.
* @param {string} config.destination - Path to the destination file.
*/
async function mirrorFile(config) {
try {
const sourceFilePath = path.resolve(config.source);
const destinationFilePath = path.resolve(config.destination);
// Read the source file
const sourceData = await readFile(sourceFilePath, 'utf8');
// Write the data to the destination file
await writeFile(destinationFilePath, sourceData, 'utf8');
console.log(`Successfully mirrored ${sourceFilePath} to ${destinationFilePath}`);
} catch (error) {
console.error(`Error mirroring file: ${error.message}`);
}
}
module.exports = mirrorFile;
Add your comment