提交 eac80723 作者: Steven Allen

implement the new GetSize methods for the filestore blockservices

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 88a38e66
......@@ -154,6 +154,22 @@ func (f *Filestore) Get(c *cid.Cid) (blocks.Block, error) {
return f.fm.Get(c)
}
// GetSize returns the size of the requested block. It may return ErrNotFound
// when the block is not stored.
func (f *Filestore) GetSize(c *cid.Cid) (int, error) {
size, err := f.bs.GetSize(c)
switch err {
default:
return -1, err
case nil:
return size, nil
case blockstore.ErrNotFound:
// try filestore
}
return f.fm.GetSize(c)
}
// Has returns true if the block with the given Cid is
// stored in the Filestore.
func (f *Filestore) Has(c *cid.Cid) (bool, error) {
......
......@@ -122,6 +122,18 @@ func (f *FileManager) Get(c *cid.Cid) (blocks.Block, error) {
return blocks.NewBlockWithCid(out, c)
}
// GetSize gets the size of the block from the datastore.
//
// This method may successfully return the size even if returning the block
// would fail because the associated file is no longer available.
func (f *FileManager) GetSize(c *cid.Cid) (int, error) {
dobj, err := f.getDataObj(c)
if err != nil {
return -1, err
}
return int(dobj.GetSize_()), nil
}
func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
if IsURL(d.GetFilePath()) {
return f.readURLDataObj(c, d)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论