Commit 4ef6493787e7e9742aad0dd4c8e2fd50d8114509
use default codec consistently
Dominic Tarr committed on 10/9/2016, 4:27:42 AMParent: 196d43450df76820243e0f92704062390929bd25
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -1,25 +1,26 @@ | ||
1 | 1 … | var fs = require('fs') |
2 | 2 … | |
3 | -var codec = { | |
3 … | +var default_codec = { | |
4 | 4 … | encode: function (obj) { |
5 | - return JSON.stringify(obj) | |
5 … | + return JSON.stringify(obj, null, 2) | |
6 | 6 … | }, |
7 | 7 … | decode: function (b) { |
8 | 8 … | return JSON.parse(b.toString()) |
9 | 9 … | } |
10 | 10 … | } |
11 | 11 … | |
12 | -module.exports = function (filename, suffix) { | |
12 … | +module.exports = function (filename, suffix, _codec) { | |
13 … | + var codec = _codec || default_codec | |
13 | 14 … | suffix = suffix || '~' |
14 | 15 … | var queue = [] |
15 | 16 … | var value |
16 | 17 … | return { |
17 | 18 … | get: function (cb) { |
18 | 19 … | if(value) return cb(null, value) |
19 | 20 … | else fs.readFile(filename, 'utf8', function (err, _value) { |
20 | 21 … | if(err) return cb(err) |
21 | - cb(null, value = JSON.parse(_value)) | |
22 … | + cb(null, value = codec.decode(_value)) | |
22 | 23 … | }) |
23 | 24 … | }, |
24 | 25 … | //only allow one update at a time. |
25 | 26 … | set: function put (_value, cb) { |
Built with git-ssb-web