/ios-ipfs-lite

Primary LanguageObjective-CMIT LicenseMIT

ios-ipfs-lite

Made by Textile Chat on Slack GitHub license Release Version License Platform CircleCI branch docs standard-readme compliant

A lightweight, extensible IPFS peer for iOS.

IPFS Lite runs the minimal setup required to get and put IPLD DAGs on the IPFS network. It is a port of the Go IPFS Lite library.

Table of Contents

Background

IPFS Lite runs the minimal setup required to provide a DAG service. It is a port of the Go IPFS Lite library, and as such, has the same requirements. The goal of IPFS Lite is to run the bare minimal functionality for any IPLD-based application to interact with the IPFS network (by getting and putting blocks). This saves having to deal with the complexities of using a full IPFS daemon, while maintaining the ability to share the underlying libp2p host and DHT with other components.

IPFS-lite Libraries

The following includes information about support for ipfs-lite.

Name Build Language Description
ipfs-lite Build Status golang The reference implementaiton of ipfs-lite, written in Go.
js-ipfs-lite Build status javascript The Javascript version of ipfs-lite available for web, nodejs, and React Native applications.
ios-ipfs-lite Build status objc The iOS ipfs-lite library for use in Objc and Swift apps
android-ipfs-lite Build status java The Java ipfs-lite library for us in Android apps
grpc-ipfs-lite Build status java A common gRPC API interface that runs on the Go ipfs-lite node.

Roadmap

  • Launch IPFS Lite
  • Stop IPFS Lite
  • addFileFromInput:params:completion: Add data via NSInputStream.
  • getFileWithCid:completion: Asynchronously get file by content address.
  • getFileToOutput:cid:completion: Asynchronously get file by content address and write it to a NSOutputStream
  • getNodeForCid:completion: Asynchronously get an IPLD node from IPFS.
  • getNodesForCids:completion: Get multiple IPLD nodes.
  • hasBlock:completion: Query if the local peer has the specified block
  • removeNodeForCid:completion: Remove an IPLD node.
  • removeNodesForCids:completion: Remove multiple IPLD nodes.
  • resolveLinkInNodeWithCid:path:completion: Resolve a link though a path in an IPLD node.
  • treeInNodeWithCid:fromPath:depth:completion: List all data paths in an IPLD node.
  • addNode And an IPLD node.
  • addNodes And multiple IPLD nodes.

Install

The IPFS Lite library is published as a Cocoapod.

First, you'll need to configure your project to use Cocoapods.

Then, simple add IpfsLiteApi to your Podfile

...
pod 'IpfsLiteApi'
...

and run pod install

Usage

Initialize and start a Peer

NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *repoPath = [documents stringByAppendingPathComponent:@"ipfs-lite"];
NSError *error;
BOOL success = [IpfsLiteApi launch:repoPath debug:false lowMem: true error:&error];

Add data

NSInputStream *input = [[NSInputStream alloc] initWithData:[@"Hello there\n" dataUsingEncoding:NSUTF8StringEncoding]];
[IpfsLiteApi.instance addFileFromInput:input parms:[[TTEAddParams alloc] init] completion:^(Node * _Nullable node, NSError * _Nullable error) {
    // handle the node or error
}];

Add a file

NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpeg"];
NSInputStream *input = [[NSInputStream alloc] initWithFileAtPath:path];
[IpfsLiteApi.instance addFileFromInput:input params:[[TTEAddParams alloc] init] completion:^(Node * _Nullable node, NSError * _Nullable error) {
    // handle the node or error
}];

Fetch a file by CID to a NSOutputStream

NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *outputPath = [documents stringByAppendingPathComponent:@"out.jpeg"];
NSOutputStream *output = [NSOutputStream outputStreamToFileAtPath:outputPath append:NO];
[IpfsLiteApi.instance getFileToOutput:output cid:@"<a-file-cid>" completion:^(NSError * _Nullable error) {
    // Handle error if it exists or interact with data written to disk
}];

Fetch a node by CID

[IpfsLiteApi.instance getNodeForCid:@"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D" completion:^(Node * _Nullable node, NSError * _Nullable error) {
    // handle the node or error
}];

Maintainers

Aaron Sutula

Contributing

See the contributing file!

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT (c) 2019 Textile