MCPcopy Index your code
hub / github.com/chartbrew/chartbrew / decryptFileSync

Function decryptFileSync

server/modules/fileEncryption.js:62–80  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

60 * @returns {Buffer} - Decrypted file content as a Buffer
61 */
62function 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
82module.exports = {
83 encryptFile,

Callers 3

createSshTunnelFunction · 0.85
createClickHouseClientFunction · 0.85

Calls 1

decryptFunction · 0.70

Tested by

no test coverage detected