Skip to content

Commit

Permalink
implement GetSize
Browse files Browse the repository at this point in the history
(also remove outdated comment, all values are []byte now)
  • Loading branch information
Stebalien committed Oct 4, 2018
1 parent b71f76e commit f3b70ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func NewDatastore(path string, opts *Options) (*datastore, error) {
}, nil
}

// Returns ErrInvalidType if value is not of type []byte.
//
// Note: using sync = false.
// see http://godoc.org/github.com/syndtr/goleveldb/leveldb/opt#WriteOptions
func (d *datastore) Put(key ds.Key, value []byte) (err error) {
Expand All @@ -73,6 +71,10 @@ func (d *datastore) Get(key ds.Key) (value []byte, err error) {
return val, nil
}

func (d *datastore) GetSize(key ds.Key) (size int, err error) {
return ds.GetBackedSize(d, key)
}

func (d *datastore) Has(key ds.Key) (exists bool, err error) {
return d.DB.Has(key.Bytes(), nil)
}
Expand Down
7 changes: 7 additions & 0 deletions ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

ds "github.com/ipfs/go-datastore"
dsq "github.com/ipfs/go-datastore/query"
dstest "github.com/ipfs/go-datastore/test"
)

var testcases = map[string]string{
Expand Down Expand Up @@ -223,3 +224,9 @@ func TestDiskUsageInMem(t *testing.T) {
t.Fatal("inmem dbs have 0 disk usage")
}
}

func TestSuite(t *testing.T) {
d := newDSMem(t)
defer d.Close()
dstest.SubtestAll(t, d)
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
},
{
"author": "jbenet",
"hash": "QmUyz7JTJzgegC6tiJrfby3mPhzcdswVtG4x58TQ6pq8jV",
"hash": "QmaRb5yNXKonhbkpNxNawoydk4N6es6b4fPj19sjEKsh5D",
"name": "go-datastore",
"version": "3.2.0"
"version": "3.4.0"
}
],
"gxVersion": "0.8.0",
Expand Down

0 comments on commit f3b70ed

Please sign in to comment.