GithubHelp home page GithubHelp logo

net-ipfs-api's Introduction

net-ipfs-api v0.3.11 beta

The .NET portable class library (PCL) for the InterPlanetary File System (IPFS) API. Currently a work in progress

This library should be easy to use if you're familiar with the IPFS CLI. Top level commands (eg. ipfs cat, ipfs add) are methods in IpfsClient. Subcommands are methods in the IPFS client's properties named after the subcommands.

ie. ipfs swarm peers becomes ipfs.Swarm.Peers() and ipfs add <file> becomes ipfs.Add(file). Easy!

The only exception is if a valid 'top level' command has subcommands, since C# can't have methods and properties with the same name. ie. ipfs config and ipfs config edit become ipfs.ConfigCommand() and ipfs.Config.Edit().

CLI arguments are required method parameters and CLI options are optional method parameters.

Examples

Adding & reading a file:

using (var ipfs = new IpfsClient())
{
  //Name of the file to add
  string fileName = "test.txt";

  //Wrap our stream in an IpfsStream, so it has a file name.
  IpfsStream inputStream = new IpfsStream(fileName, File.OpenRead(fileName));

  MerkleNode node = await ipfs.Add(inputStream);

  Stream outputStream = await ipfs.Cat(node.Hash);

  using(StreamReader sr = new StreamReader(outputStream));
  {
    string contents = sr.ReadToEnd();

    Console.WriteLine(contents); //Contents of test.txt are printed here!
  }
}

Disconnect from all peers:

using (var ipfs = new IpfsClient())
{
    var peers = await ipfs.Swarm.Peers();
    await ipfs.Swarm.Disconnect(peers);
}

Contributions

Contributions are very welcome. Create a feature branch off develop, make your changes, and raise a pull request back to develop. Unit tests encouraged.

License

MIT license, see LICENSE for details

Thanks

Thanks to @slothbag for spotting/fixing various bugs :)

net-ipfs-api's People

Contributors

trekdev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.