Skip to content

Instantly share code, notes, and snippets.

@overthemike
Created March 16, 2017 22:00
Show Gist options
  • Save overthemike/e5ba1e2c0d476e03d03a00c2e393dc2a to your computer and use it in GitHub Desktop.
Save overthemike/e5ba1e2c0d476e03d03a00c2e393dc2a to your computer and use it in GitHub Desktop.
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