pub struct LiteClient { /* private fields */ }Expand description
A light Swarm client: a read endpoint, plus an optional stamped node for uploads.
Implementations§
Source§impl LiteClient
impl LiteClient
Sourcepub fn read(endpoint: &str) -> Result<Self>
pub fn read(endpoint: &str) -> Result<Self>
Build a read client pointed at endpoint (a public gateway or any
Bee HTTP base URL).
Examples found in repository?
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}More examples
10async fn main() -> anyhow::Result<()> {
11 let file = std::env::args().nth(1).expect("usage: upload_and_feed <file>");
12 let node = std::env::var("BEE_NODE").unwrap_or_else(|_| "http://localhost:1633".into());
13 let stamp = std::env::var("BEE_STAMP").expect("set BEE_STAMP to a usable postage batch id");
14
15 // Reads use the node here too; in practice the read endpoint can be a gateway.
16 let scout = LiteClient::read(&node)?.with_write(&node, &stamp)?;
17
18 let data = std::fs::read(&file)?;
19 let file_ref = scout.up_bytes(data).await?;
20 println!("uploaded: {file_ref}");
21
22 // A throwaway feed identity for the demo; persist this key to keep the handle.
23 let (key, _owner, _pubkey) = scout::generate_key()?;
24 let handle = scout.publish(&key, "example-feed", &file_ref).await?;
25 println!("feed handle: {handle}");
26 println!("read latest: scout cat {handle} --gateway {node}");
27 Ok(())
28}Sourcepub fn with_write(self, node_endpoint: &str, stamp: &str) -> Result<Self>
pub fn with_write(self, node_endpoint: &str, stamp: &str) -> Result<Self>
Attach a write endpoint: a Bee node holding a usable postage batch
(stamp, hex). Uploads go here; reads keep using the read endpoint.
Examples found in repository?
10async fn main() -> anyhow::Result<()> {
11 let file = std::env::args().nth(1).expect("usage: upload_and_feed <file>");
12 let node = std::env::var("BEE_NODE").unwrap_or_else(|_| "http://localhost:1633".into());
13 let stamp = std::env::var("BEE_STAMP").expect("set BEE_STAMP to a usable postage batch id");
14
15 // Reads use the node here too; in practice the read endpoint can be a gateway.
16 let scout = LiteClient::read(&node)?.with_write(&node, &stamp)?;
17
18 let data = std::fs::read(&file)?;
19 let file_ref = scout.up_bytes(data).await?;
20 println!("uploaded: {file_ref}");
21
22 // A throwaway feed identity for the demo; persist this key to keep the handle.
23 let (key, _owner, _pubkey) = scout::generate_key()?;
24 let handle = scout.publish(&key, "example-feed", &file_ref).await?;
25 println!("feed handle: {handle}");
26 println!("read latest: scout cat {handle} --gateway {node}");
27 Ok(())
28}Sourcepub async fn cat(&self, reference: &str) -> Result<Vec<u8>>
pub async fn cat(&self, reference: &str) -> Result<Vec<u8>>
Download manifest-aware content at reference (GET /bzz/{ref}).
Examples found in repository?
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}Sourcepub async fn cat_path(&self, reference: &str, path: &str) -> Result<Vec<u8>>
pub async fn cat_path(&self, reference: &str, path: &str) -> Result<Vec<u8>>
Download one path inside a collection (GET /bzz/{ref}/{path}).
Examples found in repository?
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}Sourcepub async fn bytes(&self, reference: &str) -> Result<Vec<u8>>
pub async fn bytes(&self, reference: &str) -> Result<Vec<u8>>
Download raw bytes (GET /bytes/{ref}).
Sourcepub async fn up_file(
&self,
name: &str,
content_type: &str,
data: Vec<u8>,
) -> Result<String>
pub async fn up_file( &self, name: &str, content_type: &str, data: Vec<u8>, ) -> Result<String>
Upload a file (manifest-wrapped, POST /bzz). Returns the bzz
reference as hex.
Sourcepub async fn up_bytes(&self, data: Vec<u8>) -> Result<String>
pub async fn up_bytes(&self, data: Vec<u8>) -> Result<String>
Upload raw bytes (POST /bytes). Returns the bytes reference as hex.
Examples found in repository?
10async fn main() -> anyhow::Result<()> {
11 let file = std::env::args().nth(1).expect("usage: upload_and_feed <file>");
12 let node = std::env::var("BEE_NODE").unwrap_or_else(|_| "http://localhost:1633".into());
13 let stamp = std::env::var("BEE_STAMP").expect("set BEE_STAMP to a usable postage batch id");
14
15 // Reads use the node here too; in practice the read endpoint can be a gateway.
16 let scout = LiteClient::read(&node)?.with_write(&node, &stamp)?;
17
18 let data = std::fs::read(&file)?;
19 let file_ref = scout.up_bytes(data).await?;
20 println!("uploaded: {file_ref}");
21
22 // A throwaway feed identity for the demo; persist this key to keep the handle.
23 let (key, _owner, _pubkey) = scout::generate_key()?;
24 let handle = scout.publish(&key, "example-feed", &file_ref).await?;
25 println!("feed handle: {handle}");
26 println!("read latest: scout cat {handle} --gateway {node}");
27 Ok(())
28}Sourcepub async fn up_dir(
&self,
folder: &str,
index_document: Option<&str>,
) -> Result<String>
pub async fn up_dir( &self, folder: &str, index_document: Option<&str>, ) -> Result<String>
Upload a whole directory as a browsable Swarm collection (a
mantaray manifest). index_document (e.g. index.html) is served
as the default document at bzz/<ref>/. Returns the manifest
reference. Needs a write endpoint (--stamp).
Sourcepub async fn publish(
&self,
key_hex: &str,
topic: &str,
reference: &str,
) -> Result<String>
pub async fn publish( &self, key_hex: &str, topic: &str, reference: &str, ) -> Result<String>
Point a feed (key owner + topic) at reference and ensure a
feed manifest exists. Returns the manifest reference — a
stable handle that always resolves to the feed’s latest content.
Read it later with LiteClient::cat; re-publishing updates what
that same handle serves. Needs a write endpoint (--stamp).
Examples found in repository?
10async fn main() -> anyhow::Result<()> {
11 let file = std::env::args().nth(1).expect("usage: upload_and_feed <file>");
12 let node = std::env::var("BEE_NODE").unwrap_or_else(|_| "http://localhost:1633".into());
13 let stamp = std::env::var("BEE_STAMP").expect("set BEE_STAMP to a usable postage batch id");
14
15 // Reads use the node here too; in practice the read endpoint can be a gateway.
16 let scout = LiteClient::read(&node)?.with_write(&node, &stamp)?;
17
18 let data = std::fs::read(&file)?;
19 let file_ref = scout.up_bytes(data).await?;
20 println!("uploaded: {file_ref}");
21
22 // A throwaway feed identity for the demo; persist this key to keep the handle.
23 let (key, _owner, _pubkey) = scout::generate_key()?;
24 let handle = scout.publish(&key, "example-feed", &file_ref).await?;
25 println!("feed handle: {handle}");
26 println!("read latest: scout cat {handle} --gateway {node}");
27 Ok(())
28}Upload data under an ACT and grant the given compressed-pubkey
grantees. Returns the refs to download it (file_ref + history +
publisher) and to manage access (grantee_ref). Needs --stamp.
Sourcepub async fn revoke(
&self,
grantee_ref: &str,
history: &str,
remove: &[String],
) -> Result<(String, String)>
pub async fn revoke( &self, grantee_ref: &str, history: &str, remove: &[String], ) -> Result<(String, String)>
Revoke remove grantees from a grantee list anchored at the
upload’s history. Returns the new (grantee_ref, grantee_history).
Needs --stamp.