summaryrefslogtreecommitdiff
path: root/file.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2018-05-05 18:52:59 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2018-05-05 18:52:59 +0200
commit075c26e94f16379b302570e689d244edef94cb04 (patch)
tree08a0edad5703910f557707b16f8f9a032df34e84 /file.js
parent63da93e9f443a799208c8e706616a828fa528a3e (diff)
downloadbrokentalents-075c26e94f16379b302570e689d244edef94cb04.tar.gz
brokentalents-075c26e94f16379b302570e689d244edef94cb04.zip
save data to file
Diffstat (limited to 'file.js')
-rw-r--r--file.js30
1 files changed, 30 insertions, 0 deletions
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,
+};