diff --git a/lib/node-iniparser.js b/lib/node-iniparser.js index 93397a3..5627390 100644 --- a/lib/node-iniparser.js +++ b/lib/node-iniparser.js @@ -38,6 +38,15 @@ module.exports.parseSync = function(file){ return parse(fs.readFileSync(file, 'utf8')); }; +module.exports.write = function(file, data, callback){ + + fs.writeFile(file, JSONtoINI(data), function (err) { + if (err) throw err; + if(callback) callback(); + }); + +}; + function parse(data){ var value = {}; var lines = data.split(/\r\n|\r|\n/); @@ -63,4 +72,15 @@ function parse(data){ return value; } +function JSONtoINI(data) +{ + var ini = ""; + + for (key in data) { + ini += key + "=" + data[key].toString() + "\n"; + } + + return ini; +} + module.exports.parseString = parse;