From df78803833c43b0fb0925dda84094fa7fa9e61d0 Mon Sep 17 00:00:00 2001 From: Ezequias Lopes <63757378+ezequiaslopesdasilva@users.noreply.github.com> Date: Thu, 4 Aug 2022 17:54:16 +0000 Subject: [PATCH] fix: fix save method added encryption support --- handler/save.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 handler/save.js diff --git a/handler/save.js b/handler/save.js new file mode 100644 index 0000000..c20bf8a --- /dev/null +++ b/handler/save.js @@ -0,0 +1,27 @@ +const path = require('./path'); +const format = require('./format'); +const encode = require('../intermediate/encode'); +const fs = require('fs'); + +function write(path, data){ + fs.writeFileSync(path, data); +}; + +function parseContent(processed_data){ + var result = '{}'; + try { result = JSON.stringify(processed_data, null, '\t'); } + catch (err){ result = '{}' }; + return result; +}; + +function main(data, settings, cryptography){ + var parents_path = settings.parents; + var target_file = settings.name; + var current_path = path.validate(parents_path, target_file); + var formatted_content = format.compile(data); + var parsed_content = parseContent(formatted_content); + var encoded_content = encode(parsed_content, cryptography); + write(current_path, encoded_content); +}; + +module.exports = main; \ No newline at end of file