daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Jun 8th, 2018 48 in 166 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func viewAll(db *badger.DB) {
  2.     txn := db.NewTransaction(false)
  3.     defer txn.Discard()
  4.     iterOpts := badger.IteratorOptions{false, 0, false, true}
  5.     itr := txn.NewIterator(iterOpts)
  6.     defer itr.Close()
  7.     b := state.NewBucket(state.BucketRecords)
  8.     multiBuffer := capn.NewSingleSegmentMultiBuffer()
  9.     for itr.Seek(b.NewKey(nil).Bytes()); itr.Valid(); itr.Next() {
  10.         value, err := itr.Item().Value()
  11.         if err != nil {
  12.             log.Fatalln(err)
  13.         }
  14.  
  15.         read, err := capn.ReadFromMemoryZeroCopyNoAlloc(value, multiBuffer)
  16.         if err != nil {
  17.             log.Fatalln(err) // EOF error
  18.         } else if read != int64(len(value)) {
  19.             panic(fmt.Sprintf("wrong read: %d != %d", read, len(value)))
  20.         }
  21.         vv := proto.ReadRootRecord(multiBuffer.Segments[0])
  22.         out, err := vv.MarshalCapLit()
  23.         if err != nil {
  24.             log.Fatalln(err)
  25.         }
  26.         err = ioutil.WriteFile("cmd/db/content.out", out, 0777|os.ModeAppend)
  27.         if err != nil {
  28.             log.Fatalln("toFile", err)
  29.         }
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top