ferristseng / rust-ipfs-api

IPFS HTTP client in Rust
Apache License 2.0
247 stars 68 forks source link

How can I get pure file content of ipfs? #82

Closed zemelLeong closed 3 years ago

zemelLeong commented 3 years ago

I ran this code. And I got result it have a prefix. How can I get pure content?

    #[tokio::test]
    async fn ipfs_test() {
        let client = IpfsClient::from_str("http://localhost:5002").unwrap();

        let data = Cursor::new("Hello World!");
        let hash = client.add(data).await.unwrap().hash;

        println!("{:?}++++++++++++++++++++++", hash);
        let file = client.get(&format!("/ipfs/{}", hash));

        match file.map_ok(|chunk| chunk.to_vec()).try_concat().await {
            Ok(res) => {
                let out = io::stdout();
                let mut out = out.lock();

                out.write_all(&res).unwrap();
            }
            Err(e) => eprintln!("{}", e),
        }
    }
"Qmf1rtki74jvYmGeqaaV51hzeiaa6DyWc98fzDiuPatzyy"++++++++++++++++++++++
Qmf1rtki74jvYmGeqaaV51hzeiaa6DyWc98fzDiuPatzyy0000644000000000000000000000001414112126667017605 0ustar0000000000000000Hello World!
SionoiS commented 3 years ago

IPFS get is for files, IPFS cat is for raw data.

Kind of weird but that's how it works.

zemelLeong commented 3 years ago

Thanks