Skip to content

Commit

Permalink
feat: add a basic CLI for v0 CID
Browse files Browse the repository at this point in the history
  • Loading branch information
omarabid committed Apr 9, 2024
1 parent 713843d commit e60fae3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Generate IPFS CIDs (Content Identifiers) from a slice of bytes.
keywords = ["ipfs", "cid", "content", "identifier", "hash"]
authors = ["Abid Omar <[email protected]>"]
exclude = ["tests/*", "examples/*", "data/*"]
version = "1.0.0"
version = "2.0.0"
edition = "2021"
license = "MIT"
homepage = "https://github.com/omarabid/ipfs-cid"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa

The file is accessible from IPFS at the same hash: [QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa](https://ipfs.io/ipfs/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
Expand Down
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ipfs-cid is a tool to generate the CID of a file.
// The CLI is simple and only takes a file path as an argument and prints the CID to STDOUT.
pub fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 {
eprintln!("Usage: ipfs-cid <file>");
std::process::exit(1);
}
let path = &args[1];
let file = std::fs::read(path).expect("Failed to read file");
let cid = ipfs_cid::generate_cid_v0(&file);
match cid {
Ok(cid) => println!("{}", cid),
Err(e) => eprintln!("Failed to generate CID: {}", e),
}
}

0 comments on commit e60fae3

Please sign in to comment.