Struct IpfsApi

Source
pub struct IpfsApi { /* private fields */ }

Implementations§

Source§

impl IpfsApi

Source

pub fn cat(&self, hash: &str) -> Result<impl Iterator<Item = u8>, Error>

Retrieves the contents of a file from the IPFS network. Takes a hash and returns an iterator of bytes. The result can be streamed, if the file is large.

let api = IpfsApi::new("127.0.0.1", 5001);

let hello = api.cat("QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u")?;
let hello_string = String::from_utf8(hello.collect())?;
println!("{}", hello_string);
Examples found in repository?
examples/hello_world.rs (line 9)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    let bytes = api
9        .cat("QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u")
10        .unwrap();
11    let data = String::from_utf8(bytes.collect()).unwrap();
12
13    println!("{}", data);
14}
Source§

impl IpfsApi

Source

pub fn shutdown(&self) -> Result<(), Error>

Shut down the IPFS daemon This function causes the IPFS daemon to terminate

Source§

impl IpfsApi

Source

pub fn version(&self) -> Result<IpfsVersion, Box<dyn Error>>

Get the version from the IPFS daemon.

Examples found in repository?
examples/get_version.rs (line 8)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    match api.version() {
9        Ok(ver) => println!("{:?}", ver.version()),
10        Err(_) => println!("Cannot connect to IPFS daemon"),
11    }
12}
Source§

impl IpfsApi

Source

pub fn block_get(&self, hash: &str) -> Result<impl Iterator<Item = u8>, Error>

Get a raw IPFS block.

§Notes

This is a wrapper for the /api/v0/block/get API.

§Errors

This function can return an error if the IPFS node is down, or if the block cannot be retrieved.

§Examples
let api = IpfsApi::new("127.0.0.1", 5001);

let hash = "QmV8cfu6n4NT5xRr2AHdKxFMTZEJrA44qgrBCr739BN9Wb";
let block = api.block_get(hash).unwrap();
let string = String::from_utf8(block.collect()).unwrap();

assert_eq!(string, "Hello world");
Source§

impl IpfsApi

Source

pub fn block_put(&self, data: &[u8]) -> Result<String, Box<dyn Error>>

Puts a raw block into IPFS.

§Notes

This is a wrapper for the /api/v0/block/put API.

Source§

impl IpfsApi

Source

pub fn name_publish(&self, hash: &str) -> Result<(), Box<dyn Error>>

Publish an IPFS hash in IPNS.

Source§

impl IpfsApi

Source

pub fn name_resolve(&self, name: &str) -> Result<String, Box<dyn Error>>

Resolve an IPNS hash or a domain name

let api = IpfsApi::new("127.0.0.1", 5001);
let hash = api.name_resolve("gkbrk.com")?;

println!("{}", hash);
Examples found in repository?
examples/ipns_resolve.rs (line 8)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    let hash = api.name_resolve("gkbrk.com").unwrap();
9
10    println!("{}", hash);
11}
Source§

impl IpfsApi

Source

pub fn pin_add(&self, hash: &str) -> Result<Vec<String>, Box<dyn Error>>

Publish an IPFS hash in IPNS.

Source§

impl IpfsApi

The main interface of the library The IpfsApi class represents a connection to the local IPFS daemon. It can read and write data to it using http requests to the server.

Source

pub fn new(server: &str, port: u16) -> Self

Creates a new instance of the API

let api = IpfsApi::new("127.0.0.1", 5001);
Examples found in repository?
examples/ipns_resolve.rs (line 6)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    let hash = api.name_resolve("gkbrk.com").unwrap();
9
10    println!("{}", hash);
11}
More examples
Hide additional examples
examples/log.rs (line 6)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    //let logs = api.log_tail().unwrap();
9
10    //for log_line in logs {
11    //    println!("{:?}", log_line);
12    //}
13}
examples/chat_read.rs (line 6)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    //let messages = api.pubsub_subscribe("chat").unwrap();
9
10    //for message in messages {
11    //    println!("{:?}", message);
12    //}
13}
examples/get_version.rs (line 6)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    match api.version() {
9        Ok(ver) => println!("{:?}", ver.version()),
10        Err(_) => println!("Cannot connect to IPFS daemon"),
11    }
12}
examples/hello_world.rs (line 6)
5fn main() {
6    let api = IpfsApi::new("127.0.0.1", 5001);
7
8    let bytes = api
9        .cat("QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u")
10        .unwrap();
11    let data = String::from_utf8(bytes.collect()).unwrap();
12
13    println!("{}", data);
14}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.