提交 144bbb65 作者: Steven Allen

add GetSize method to the v0v1 blockstore

fixes hidden merge conflict

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 92099a2e
......@@ -2,9 +2,9 @@ package cidv0v1
import (
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
bs "gx/ipfs/QmTCHqj6s51pDu1GaPGyBW2VdmCUvtzLCF6nWykfX9ZYRt/go-ipfs-blockstore"
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
bs "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
)
type blockstore struct {
......@@ -57,6 +57,21 @@ func (b *blockstore) Get(c *cid.Cid) (blocks.Block, error) {
return block, nil
}
func (b *blockstore) GetSize(c *cid.Cid) (int, error) {
size, err := b.Blockstore.GetSize(c)
if err == nil {
return size, nil
}
if err != bs.ErrNotFound {
return -1, err
}
c1 := tryOtherCidVersion(c)
if c1 == nil {
return -1, bs.ErrNotFound
}
return b.Blockstore.GetSize(c1)
}
func tryOtherCidVersion(c *cid.Cid) *cid.Cid {
prefix := c.Prefix()
if prefix.Codec != cid.DagProtobuf || prefix.MhType != mh.SHA2_256 || prefix.MhLength != 32 {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论