storage/boltdb.go | 14 ++++++++------ diff --git a/storage/boltdb.go b/storage/boltdb.go index a198f4888a332c8c964f694c5c848cc9795591de..f65382b3ff57f67b7813912cb6daad6ab456fbe1 100644 --- a/storage/boltdb.go +++ b/storage/boltdb.go @@ -10,6 +10,8 @@ "github.com/anacrolix/torrent/metainfo" ) +const chunkSize = 1 << 14 + var ( data = []byte("data") completed = []byte("completed") @@ -85,12 +87,12 @@ db := tx.Bucket(data) if db == nil { return nil } - ci := off / (1 << 14) - off %= 1 << 14 + ci := off / chunkSize + off %= chunkSize for len(b) != 0 { ck := me.chunkKey(int(ci)) _b := db.Get(ck[:]) - if len(_b) != 1<<14 { + if len(_b) != chunkSize { break } n1 := copy(b, _b[off:]) @@ -124,10 +126,10 @@ db, err := tx.CreateBucketIfNotExists(data) if err != nil { return err } - ci := off / (1 << 14) - off %= 1 << 14 + ci := off / chunkSize + off %= chunkSize for len(b) != 0 { - _b := make([]byte, 1<<14) + _b := make([]byte, chunkSize) ck := me.chunkKey(int(ci)) copy(_b, db.Get(ck[:])) n1 := copy(_b[off:], b)