https://github.com/textileio/ios-ipfs-lite
https://github.com/textileio/ios-ipfs-lite
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/textileio/ios-ipfs-lite
- Owner: textileio
- License: mit
- Created: 2019-11-08T02:31:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-06T07:59:50.000Z (almost 4 years ago)
- Last Synced: 2024-04-25T06:01:10.391Z (over 2 years ago)
- Language: Objective-C
- Size: 5.16 MB
- Stars: 61
- Watchers: 4
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ios-ipfs-lite
[](https://textile.io)
[](https://slack.textile.io)
[](./LICENSE)
[](https://github.com/textileio/ios-ipfs-lite/releases/latest)
[](https://cocoapods.org/pods/IpfsLiteApi)
[](https://cocoapods.org/pods/IpfsLiteApi)
[](https://cocoapods.org/pods/IpfsLiteApi)
[](https://circleci.com/gh/textileio/ios-ipfs-lite)
[](https://textileio.github.io/ios-ipfs-lite/)
[](https://github.com/RichardLitt/standard-readme)
> 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](https://github.com/hsanjuan/ipfs-lite) library.
## Table of Contents
- [ios-ipfs-lite](#ios-ipfs-lite)
- [Table of Contents](#table-of-contents)
- [Background](#background)
- [IPFS-lite Libraries](#ipfs-lite-libraries)
- [Roadmap](#roadmap)
- [Install](#install)
- [Usage](#usage)
- [Initialize and start a Peer](#initialize-and-start-a-peer)
- [Add data](#add-data)
- [Add a file](#add-a-file)
- [Fetch a file by CID to a NSOutputStream](#fetch-a-file-by-cid-to-a-nsoutputstream)
- [Fetch a node by CID](#fetch-a-node-by-cid)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)
## Background
IPFS Lite runs the minimal setup required to provide a DAG service. It is a port of the [Go IPFS Lite](https://github.com/hsanjuan/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`](https://github.com/hsanjuan/ipfs-lite) | [](https://travis-ci.org/hsanjuan/ipfs-lite) | [](https://github.com/hsanjuan/ipfs-lite) | The reference implementaiton of ipfs-lite, written in Go. |
| [`js-ipfs-lite`](//github.com/textileio/js-ipfs-lite) | [](https://github.com/textileio/js-ipfs-lite/actions?query=branch%3Amaster) | [](https://github.com/textileio/js-ipfs-lite)| The Javascript version of ipfs-lite available for web, nodejs, and React Native applications. |
| [`ios-ipfs-lite`](//github.com/textileio/ios-ipfs-lite) | [](https://github.com/textileio/ios-ipfs-lite/actions?query=branch%3Amaster) | [](https://github.com/textileio/ios-ipfs-lite)| The iOS ipfs-lite library for use in Objc and Swift apps |
| [`android-ipfs-lite`](//github.com/textileio/android-ipfs-lite) | [](https://github.com/textileio/android-ipfs-lite/actions?query=branch%3Amaster) | [](https://github.com/textileio/android-ipfs-lite)| The Java ipfs-lite library for us in Android apps |
| [`grpc-ipfs-lite`](//github.com/textileio/grpc-ipfs-lite) | [](https://github.com/textileio/grpc-ipfs-lite/actions?query=branch%3Amaster) | [](https://github.com/textileio/grpc-ipfs-lite)| A common gRPC API interface that runs on the Go ipfs-lite node. |
## Roadmap
- [x] Launch IPFS Lite
- [x] Stop IPFS Lite
- [x] `addFileFromInput:params:completion:` Add data via `NSInputStream`.
- [x] `getFileWithCid:completion:` Asynchronously get file by content address.
- [x] `getFileToOutput:cid:completion:` Asynchronously get file by content address and write it to a `NSOutputStream`
- [x] `getNodeForCid:completion:` Asynchronously get an IPLD node from IPFS.
- [x] `getNodesForCids:completion:` Get multiple IPLD nodes.
- [x] `hasBlock:completion:` Query if the local peer has the specified block
- [x] `removeNodeForCid:completion:` Remove an IPLD node.
- [x] `removeNodesForCids:completion:` Remove multiple IPLD nodes.
- [x] `resolveLinkInNodeWithCid:path:completion:` Resolve a link though a path in an IPLD node.
- [x] `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](https://guides.cocoapods.org/using/getting-started.html#getting-started).
Then, simple add `IpfsLiteApi` to your `Podfile`
```cmd
...
pod 'IpfsLiteApi'
...
```
and run `pod install`
## Usage
### Initialize and start a Peer
```objc
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
```objc
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
```objc
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
```objc
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:@"" completion:^(NSError * _Nullable error) {
// Handle error if it exists or interact with data written to disk
}];
```
### Fetch a node by CID
```objc
[IpfsLiteApi.instance getNodeForCid:@"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D" completion:^(Node * _Nullable node, NSError * _Nullable error) {
// handle the node or error
}];
```
## Maintainers
[Aaron Sutula](https://github.com/asutula)
## Contributing
See [the contributing file](CONTRIBUTING.md)!
PRs accepted.
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
[MIT](LICENSE) (c) 2019 Textile