hsanjuan / ipfs-lite

IPFS-Lite is an embeddable, lightweight IPFS-network peer for IPLD applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add File wrapped in Directory

cbluth opened this issue · comments

would it be possible to add a file wrapped in a directory with this library?

No, but I'm sure it is not too difficult to create the wrapping node and add that as well:

https://godoc.org/github.com/ipfs/go-unixfs#EmptyDirNode
https://godoc.org/github.com/ipfs/go-merkledag#ProtoNode.AddRawLink

@hsanjuan

i have an issue here: distributed-mind/pagesaver#2

i would like to move my project to ipfslite, but i would like to specify filenames of the files i add to ipfs

@cbluth I am saying that your problem is easily solvable outside ipfs-lite. And that I would start by trying something like:

// peer is the ipfs-lite peer instance
node := peer.AddFile(...) // add the file
emptyDir := unixfs.EmptyDirNode()
emptyDir.AddNodeLink("YOUR FILE NAME", node)
peer.Add(emptyDir) // add the wrapping folder

// emptyDir.Cid() should be the cid of the wrapping folder.

@hsanjuan

ah, right, thanks for straight forward response, and the code snippet!