Created
February 22, 2015 23:30
-
-
Save GregIngelmo/a0b6b023bea4d9f7d692 to your computer and use it in GitHub Desktop.
Bolt #299
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
package main | |
import ( | |
"log" | |
"os" | |
"github.com/boltdb/bolt" | |
) | |
var path = "bolt.db" | |
func main() { | |
os.Remove(path) | |
var val []byte | |
// 255.996055603 MiB ... no problem | |
val = make([]byte, 268431320) | |
writeKey("testkey", val) | |
// 255.9960565567 MiB ... panic | |
val = make([]byte, 268431321) | |
writeKey("testkey", val) | |
} | |
func writeKey(key string, val []byte) { | |
db, err := bolt.Open(path, 0600, nil) | |
defer db.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = db.Update(func(tx *bolt.Tx) error { | |
bucket, _ := tx.CreateBucketIfNotExists([]byte("testbucket")) | |
err := bucket.Put([]byte(key), val) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment