add GetSize method to the v0v1 blockstore
fixes hidden merge conflict License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Aug 8, 2018 at 10:21 UTC
144bbb6555ea0dbcfa02fe78b5cad0a657e42798
1 file changed
+16
-1
thirdparty/cidv0v1/blockstore.go
+16
-1
@@ -2,9 +2,9 @@ package cidv0v1
2
3
import (
4
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
5
+ bs "gx/ipfs/QmTCHqj6s51pDu1GaPGyBW2VdmCUvtzLCF6nWykfX9ZYRt/go-ipfs-blockstore"
6
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
7
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
7
- bs "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
8
)
9
10
type blockstore struct {
@@ -57,6 +57,21 @@ func (b *blockstore) Get(c *cid.Cid) (blocks.Block, error) {
57
return block, nil
58
}
59
60
+func (b *blockstore) GetSize(c *cid.Cid) (int, error) {
61
+ size, err := b.Blockstore.GetSize(c)
62
+ if err == nil {
63
+ return size, nil
64
+ }
65
+ if err != bs.ErrNotFound {
66
+ return -1, err
67
+ }
68
+ c1 := tryOtherCidVersion(c)
69
+ if c1 == nil {
70
+ return -1, bs.ErrNotFound
71
+ }
72
+ return b.Blockstore.GetSize(c1)
73
+}
74
+
75
func tryOtherCidVersion(c *cid.Cid) *cid.Cid {
76
prefix := c.Prefix()
77
if prefix.Codec != cid.DagProtobuf || prefix.MhType != mh.SHA2_256 || prefix.MhLength != 32 {