IPFS file system

The official name is UnixFSarrow-up-right. It allows files and directories of any size to be added and retrieved from IPFS via the FileSystemarrow-up-right and Objectarrow-up-right API.

Files

A file has a unique content id (CID)arrow-up-right which is the cryptographic hash of the content; see CID conceptarrow-up-right for background information. The file's content is not just the file's data but is encapsulated with a protocol bufferarrow-up-right encoding of the PBNodearrow-up-right and UnixFS Dataarrow-up-right.

Where

  • PBNode.Data contains unixfs message Data

  • unixfs Data.Data contans file's data

When the file's data exceeds the chunking sizearrow-up-right, multiple blocksarrow-up-right are generated. The returned CID points to a block that has PBNode.Links and no PBNode.Data.

Adding a file

AddAsyncarrow-up-right is used to add a stream of data to IPFS. It returns a FileSystemNodearrow-up-right which describes the added the data. Of particular import is its CIDarrow-up-right. The helper methods AddTextAsyncarrow-up-right and AddFileAsyncarrow-up-right are also available.

All the Add methods accept optionsarrow-up-right to control how the data is added to IPFS.

var fsn = await ipfs.FileSystem.AddTextAsync("hello world");
Console.WriteLine((string)fsn.Id)

// Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD

Reading a file

ReaFileAsyncarrow-up-right is used to read a stream of data from IPFS. It returns a Streamarrow-up-right containing just the file's data NOT the protocol buffer encoded data.

Getting a CID

Normally, you get the CID by addingarrow-up-right the file to IPFS. You can avoid adding it to IPFS by using the OnlyHash optionarrow-up-right.

Last updated