From 075c26e94f16379b302570e689d244edef94cb04 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 5 May 2018 18:52:59 +0200 Subject: save data to file --- file.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 file.js (limited to 'file.js') diff --git a/file.js b/file.js new file mode 100644 index 0000000..16f2c94 --- /dev/null +++ b/file.js @@ -0,0 +1,30 @@ +#!/usr/bin/node + +const R = require('ramda'), + Future = require('fluture') + fsPath = require('fs-path'); + +function loadFPayloads(config) { + return R.curry((file) => + Future.node((cb) => fsPath.readFile(file, 'utf8', cb)) + .chain(Future.encase(JSON.parse)) + ); +} + +function saveFPayloads(config) { + return R.curry((file, data) => + Future.node((cb) => fsPath.writeFile(file, JSON.stringify(data), cb)) + ); +} + +function saveFPayloadsTimestamped(config) { + return R.curry((timestamp, data) => + saveFPayloads(config)(config.pattern(timestamp), data) + ); +} + +module.exports = { + loadFPayloads, + saveFPayloads, + saveFPayloadsTimestamped, +}; -- cgit v1.3.1