Skip to content

Commit

Permalink
handle empty files (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott authored Nov 5, 2021
1 parent ef86491 commit b9b6e9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/builder/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func estimateDirSize(entries []dagpb.PBLink) int {
cl, ok := lnk.(cidlink.Link)
if ok {
s += cl.ByteLen()
} else if lnk == nil {
s += 0
} else {
s += len(lnk.Binary())
}
Expand Down
5 changes: 5 additions & 0 deletions data/builder/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func BuildUnixFSFile(r io.Reader, chunker string, ls *ipld.LinkSystem) (ipld.Lin
}

if prev != nil && prev[0] == root {
if root == nil {
node := basicnode.NewBytes([]byte{})
link, err := ls.Store(ipld.LinkContext{}, leafLinkProto, node)
return link, 0, err
}
return root, size, nil
}

Expand Down

0 comments on commit b9b6e9d

Please sign in to comment.