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

feat: cid metadata #142

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion file/unixfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unixfile
import (
"context"
"errors"
"github.com/ipfs/go-cid"

ft "github.com/ipfs/go-unixfs"
uio "github.com/ipfs/go-unixfs/io"
Expand Down Expand Up @@ -122,14 +123,36 @@ func (d *ufsDirectory) Size() (int64, error) {
return d.size, nil
}

func (d *ufsDirectory) Cid() cid.Cid {
nd, err := d.dir.GetNode()
if err != nil {
return cid.Undef
}
return nd.Cid()
}

type ufsFile struct {
uio.DagReader
nd ipld.Node
}

func (f *ufsFile) Size() (int64, error) {
return int64(f.DagReader.Size()), nil
}

func (f *ufsFile) Cid() cid.Cid {
return f.nd.Cid()
}

type ufsSymLink struct {
files.File
nd ipld.Node
}

func (s *ufsSymLink) Cid() cid.Cid {
return s.nd.Cid()
}

func newUnixfsDir(ctx context.Context, dserv ipld.DAGService, nd *dag.ProtoNode) (files.Directory, error) {
dir, err := uio.NewDirectoryFromNode(dserv, nd)
if err != nil {
Expand Down Expand Up @@ -161,7 +184,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi
return newUnixfsDir(ctx, dserv, dn)
}
if fsn.Type() == ft.TSymlink {
return files.NewLinkFile(string(fsn.Data()), nil), nil
return &ufsSymLink{File: files.NewLinkFile(string(fsn.Data()), nil), nd: nd}, nil
}

case *dag.RawNode:
Expand All @@ -176,6 +199,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi

return &ufsFile{
DagReader: dr,
nd: nd,
}, nil
}

Expand Down