Skip to content

Commit

Permalink
DISK-FORMAT-BREAKING: use base64 for state; plays nice with level enc…
Browse files Browse the repository at this point in the history
…odings
  • Loading branch information
hackergrrl committed May 26, 2019
1 parent f4fbfcf commit fdf775d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ function createIndex (ldb, opts) {
},

storeState: function (state, cb) {
state = state.toString('base64')
ldb.put('state', state, cb)
},

fetchState: function (cb) {
ldb.get('state', function (err, state) {
if (err && err.notFound) cb()
else if (err) cb(err)
else cb(null, state)
else cb(null, Buffer.from(state, 'base64'))
})
}
}
Expand Down

5 comments on commit fdf775d

@vweevers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noffle I'm probably missing context but if it helps, you could also do:

db.put('state', state, { valueEncoding: 'binary' }, cb)
db.get('state', { valueEncoding: 'binary' }, cb)

Saves an encoding step.

Also, memdb is outdated, succeeded by level-mem (same interface)

@hackergrrl
Copy link
Member Author

@hackergrrl hackergrrl commented on fdf775d May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vweevers, that's what I tried first, but gets were returning something like { type: 'Buffer', data: [...] } instead of a Buffer object.

@vweevers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noffle I'd like to take a closer look at that. How can I reproduce it?

@hackergrrl
Copy link
Member Author

@hackergrrl hackergrrl commented on fdf775d May 28, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vweevers
Copy link

@vweevers vweevers commented on fdf775d May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unable to reproduce: https://github.com/vweevers/kappa-test123 (npm i && node test)

Please sign in to comment.