diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2018-05-07 09:06:04 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2018-05-07 09:06:04 +0200 |
| commit | 5caf4e48174533710243e8eeaf52567795ec9d01 (patch) | |
| tree | 1396f09bd14c3c4e1af3164ef924f2190b3f949f /backend/file.js | |
| parent | ded191658af266a764332b9a1b72d628de3d5b6e (diff) | |
| download | brokentalents-5caf4e48174533710243e8eeaf52567795ec9d01.tar.gz brokentalents-5caf4e48174533710243e8eeaf52567795ec9d01.zip | |
move files to backend subdir, push data in submodule
Diffstat (limited to 'backend/file.js')
| -rw-r--r-- | backend/file.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/backend/file.js b/backend/file.js new file mode 100644 index 0000000..b750921 --- /dev/null +++ b/backend/file.js @@ -0,0 +1,39 @@ +#!/usr/bin/node + +const R = require('ramda'), + Future = require('fluture'), + fs = require('fs'), + fsPath = require('fs-path'); + +function loadFPayloads(config) { + return R.curry((file) => + Future.node((cb) => fs.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)) + .map(() => data) + ); +} + +function saveFPayloadsTimestamped(config) { + return R.curry((timestamp, data) => + saveFPayloads(config)(config.pattern(timestamp), data) + ); +} + +function loadFPayloadsTimestamped(config) { + return R.curry((timestamp) => + loadFPayloads(config)(config.pattern(timestamp)) + ); +} + +module.exports = { + loadFPayloads, + loadFPayloadsTimestamped, + saveFPayloads, + saveFPayloadsTimestamped, +}; |
