Created
March 16, 2017 22:00
-
-
Save overthemike/e5ba1e2c0d476e03d03a00c2e393dc2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _fs from 'fs' | |
import {encrypt, decrypt} from './encryption' | |
import low from 'lowdb' | |
export default class ReadWrite { | |
constructor(datafile, key) { | |
this.key = key | |
this.datafile = datafile | |
this.db = low(datafile, { | |
deserialize: (str) => { | |
const decrypted = decrypt(str, this.key) | |
const obj = JSON.parse(decrypted) | |
return obj | |
}, | |
serialize: (obj) => { | |
const str = JSON.stringify(obj) | |
const encrypted = encrypt(str, this.key) | |
return encrypted | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment