Skip to content

Commit

Permalink
fix: fix save method added encryption support
Browse files Browse the repository at this point in the history
  • Loading branch information
silvaezequias committed Aug 4, 2022
1 parent 6b35f90 commit df78803
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions handler/save.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit df78803

Please sign in to comment.