* Synchronously decrypts a file and returns the content * Handles both encrypted and unencrypted (legacy) files * For use in places where async/await cannot be used * @param {string} filePath - Path to the file * @returns {Buffer} - Decrypted file content as a Buffer
(filePath)
| 60 | * @returns {Buffer} - Decrypted file content as a Buffer |
| 61 | */ |
| 62 | function decryptFileSync(filePath) { |
| 63 | try { |
| 64 | // Read the file |
| 65 | const fileContent = fsSync.readFileSync(filePath, "utf8"); |
| 66 | |
| 67 | try { |
| 68 | // Try to decrypt assuming it's encrypted |
| 69 | const decryptedContent = decrypt(fileContent); |
| 70 | return Buffer.from(decryptedContent, "base64"); |
| 71 | } catch (decryptError) { |
| 72 | // If decryption fails, assume it's an unencrypted legacy file |
| 73 | // and return the content directly as a buffer |
| 74 | return Buffer.from(fileContent); |
| 75 | } |
| 76 | } catch (error) { |
| 77 | console.error(`Error reading/decrypting file ${filePath}:`, error); // oxlint-disable-line no-console |
| 78 | throw error; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | module.exports = { |
| 83 | encryptFile, |
no test coverage detected