#cid #ipfs #identifier #content #hash

bin+lib ipfs-cid

Generate IPFS CIDs (Content Identifiers) from a slice of bytes

2 stable releases

2.0.0 Apr 9, 2024
1.0.0 Jul 6, 2023

#9 in #cid

Download history 3/week @ 2024-02-15 10/week @ 2024-02-22 4/week @ 2024-02-29 12/week @ 2024-03-28 126/week @ 2024-04-04 23/week @ 2024-04-11

161 downloads per month

MIT license

12KB
107 lines

ipfs-cid

This crates provides a simple function to generate IPFS CIDs (Content Identifiers) from a slice of bytes.

What is a CID?

CI Crates.io

Usage

Two functions are available: generate_cid and generate_cid_hash. The first one returns the full CID object as defined in the cid crate (version 0.5.1). The second one returns the hash only as a String.

    let bytes_vector = std::fs::read("data/file0").unwrap();
    let bytes_slice = bytes_vector.as_slice();

    let cid_hash = generate_cid_hash(bytes_slice).unwrap();
    println!("{}", cid_hash);

This should return

QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa

The file is accessible from IPFS at the same hash: QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa

CLI

A basic CLI is avaiable in 2.0.0. It returns v0 CID of the passed file.

Usage

$ ipfs-cid file

License

This project is licensed under

Dependencies

~4–12MB
~126K SLoC