added dump/restore and fixed title stuff

This commit is contained in:
ston1th 2018-10-16 21:26:39 +02:00
commit 8d3187b160
13 changed files with 200627 additions and 189988 deletions

View file

@ -34,8 +34,8 @@ func NewBoltStore(file string, m Marshaler) (bs *BoltStore, err error) {
}
type dump struct {
k string `json:"k"`
v []byte `json:"v"`
K string `json:"k"`
V []byte `json:"v"`
}
func (bs *BoltStore) Dump(w io.Writer) (err error) {
@ -44,7 +44,9 @@ func (bs *BoltStore) Dump(w io.Writer) (err error) {
}
var d []dump
err = bs.ForEach(func(k string, v []byte) error {
d = append(d, dump{k, v})
b := make([]byte, len(v))
copy(b, v)
d = append(d, dump{k, b})
return nil
})
if err != nil {
@ -74,7 +76,7 @@ func (bs *BoltStore) Restore(r io.Reader) (err error) {
return bs.db.Update(func(tx *bolt.Tx) (err error) {
b := tx.Bucket([]byte(defaultBoltBucket))
for _, v := range d {
b.Put([]byte(v.k), v.v)
b.Put([]byte(v.K), v.V)
}
return nil
})