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

Commit 7e96bad

Browse files
author
Cory Schwartz
committed
Fix in size func
1 parent 77ff92d commit 7e96bad

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

io/dagreader.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,9 @@ func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagRe
5656
}
5757

5858
switch fsNode.Type() {
59-
case unixfs.TFile:
59+
case unixfs.TFile, unixfs.TRaw:
6060
size = fsNode.FileSize()
6161

62-
case unixfs.TRaw:
63-
stat, err := n.Stat()
64-
if err != nil {
65-
return nil, err
66-
}
67-
size = uint64(stat.DataSize)
68-
for _, link := range n.Links() {
69-
ln, err := link.GetNode(ctx, serv)
70-
if err != nil {
71-
return nil, err
72-
}
73-
stat, err := ln.Stat()
74-
if err != nil {
75-
return nil, err
76-
}
77-
size += uint64(stat.DataSize)
78-
}
79-
8062
case unixfs.TDirectory, unixfs.THAMTShard:
8163
// Dont allow reading directories
8264
return nil, ErrIsDir

unixfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ func size(pbdata *pb.Data) (uint64, error) {
159159
switch pbdata.GetType() {
160160
case pb.Data_Directory, pb.Data_HAMTShard:
161161
return 0, errors.New("can't get data size of directory")
162-
case pb.Data_File:
162+
case pb.Data_File, pb.Data_Raw:
163163
return pbdata.GetFilesize(), nil
164-
case pb.Data_Symlink, pb.Data_Raw:
164+
case pb.Data_Symlink:
165165
return uint64(len(pbdata.GetData())), nil
166166
default:
167167
return 0, errors.New("unrecognized node data type")

0 commit comments

Comments
 (0)