Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
io/dagreader.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Schwartz committed Apr 16, 2021
1 parent 68c015a commit 77ff92d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion io/dagreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,27 @@ func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagRe
}

switch fsNode.Type() {
case unixfs.TFile, unixfs.TRaw:
case unixfs.TFile:
size = fsNode.FileSize()

case unixfs.TRaw:
stat, err := n.Stat()
if err != nil {
return nil, err
}
size = uint64(stat.DataSize)
for _, link := range n.Links() {
ln, err := link.GetNode(ctx, serv)
if err != nil {
return nil, err
}
stat, err := ln.Stat()
if err != nil {
return nil, err
}
size += uint64(stat.DataSize)
}

case unixfs.TDirectory, unixfs.THAMTShard:
// Dont allow reading directories
return nil, ErrIsDir
Expand Down

0 comments on commit 77ff92d

Please sign in to comment.