Skip to main content

read/
read.rs

1//! Read content from Swarm with no node — just a gateway.
2//!
3//!   cargo run --example read -- <reference>
4//!   BEE_GATEWAY=https://download.gateway.ethswarm.org cargo run --example read -- <ref>
5
6use scout::LiteClient;
7
8#[tokio::main]
9async fn main() -> anyhow::Result<()> {
10    let reference = std::env::args()
11        .nth(1)
12        .expect("usage: read <reference> [path]");
13    let path = std::env::args().nth(2);
14    let gateway = std::env::var("BEE_GATEWAY")
15        .unwrap_or_else(|_| "https://download.gateway.ethswarm.org".into());
16
17    let scout = LiteClient::read(&gateway)?;
18    let data = match &path {
19        Some(p) => scout.cat_path(&reference, p).await?,
20        None => scout.cat(&reference).await?,
21    };
22    print!("{}", String::from_utf8_lossy(&data));
23    Ok(())
24}