Skip to main content

FileApi

Struct FileApi 

Source
pub struct FileApi { /* private fields */ }
Expand description

Handle exposing the file/data/chunk endpoints. Cheap to clone (holds an Arc<Inner>).

Implementations§

Source§

impl FileApi

Source

pub async fn upload_file( &self, batch_id: &BatchId, data: impl Into<Bytes>, name: &str, content_type: &str, opts: Option<&FileUploadOptions>, ) -> Result<UploadResult, Error>

Upload a single file via POST /bzz. name is sent as the name= query parameter (Bee uses it as the filename in Content-Disposition on download). When content_type is empty and opts does not specify one, application/octet-stream is used.

Source

pub async fn download_file( &self, reference: &Reference, opts: Option<&DownloadOptions>, ) -> Result<(Bytes, FileHeaders), Error>

Download a file via GET /bzz/{ref}. Returns the body bytes plus the parsed FileHeaders (filename / content-type / tag UID).

Source

pub async fn download_file_response( &self, reference: &Reference, opts: Option<&DownloadOptions>, ) -> Result<Response, Error>

Same as FileApi::download_file but returns the raw reqwest::Response for streaming. The caller drives reading from resp.bytes_stream() or resp.chunk().

Source

pub async fn download_file_path( &self, reference: &Reference, path: &str, opts: Option<&DownloadOptions>, ) -> Result<(Bytes, FileHeaders), Error>

Download a path inside a collection via GET /bzz/{ref}/{path}. Useful for serving individual files of a previously uploaded site.

Source

pub async fn upload_collection_entries( &self, batch_id: &BatchId, entries: &[CollectionEntry], opts: Option<&CollectionUploadOptions>, ) -> Result<UploadResult, Error>

Upload an in-memory collection (vec of CollectionEntry) as a tar stream via POST /bzz. Mirrors bee-go’s UploadCollectionEntries and bee-js’s makeCollectionFromFileList + bzz.uploadCollection.

Source

pub async fn upload_collection( &self, batch_id: &BatchId, dir: impl AsRef<Path>, opts: Option<&CollectionUploadOptions>, ) -> Result<UploadResult, Error>

Walk the filesystem at dir, build a tar archive of every regular file (relative paths preserved), and upload it via POST /bzz. Symlinks and special files are skipped. Mirrors bee-go’s UploadCollection.

Source§

impl FileApi

Source

pub async fn upload_chunk( &self, batch_id: &BatchId, data: impl Into<Bytes>, opts: Option<&UploadOptions>, ) -> Result<UploadResult, Error>

Upload a single raw chunk (span || payload) via POST /chunks.

Source

pub async fn download_chunk( &self, reference: &Reference, opts: Option<&DownloadOptions>, ) -> Result<Bytes, Error>

Download a single chunk’s bytes via GET /chunks/{ref}.

Source§

impl FileApi

Source

pub async fn chunks_stream( &self, batch_id: &BatchId, tag: Option<u64>, ) -> Result<ChunkStream, Error>

Open a /chunks/stream websocket upload session against the configured Bee node.

  • batch_id is sent in the Swarm-Postage-Batch-Id header and is used to stamp every chunk uploaded over this socket.
  • tag (optional) is the existing tag UID to associate with the upload via the swarm-tag query parameter; without a tag, chunks are forwarded to the network as they arrive.
Source§

impl FileApi

Source

pub async fn upload_data( &self, batch_id: &BatchId, data: impl Into<Bytes>, opts: Option<&RedundantUploadOptions>, ) -> Result<UploadResult, Error>

Upload raw bytes via POST /bytes. The body is sent as application/octet-stream. Returns an UploadResult with the content reference, optional tag UID, and (when ACT was requested) the history address.

§Examples
use bee::Client;
use bee::swarm::BatchId;
use bytes::Bytes;

let client = Client::new("http://localhost:1633")?;
let result = client
    .file()
    .upload_data(&batch_id, Bytes::from_static(b"Hello Swarm!"), None)
    .await?;
println!("reference: {}", result.reference.to_hex());
Source

pub async fn download_data( &self, reference: &Reference, opts: Option<&DownloadOptions>, ) -> Result<Bytes, Error>

Download raw bytes via GET /bytes/{ref}. Returns the full body in memory. For streaming downloads use FileApi::download_data_response.

§Examples
use bee::Client;
use bee::swarm::Reference;

let client = Client::new("http://localhost:1633")?;
let body = client.file().download_data(&reference, None).await?;
println!("downloaded {} bytes", body.len());
Source

pub async fn download_data_response( &self, reference: &Reference, opts: Option<&DownloadOptions>, ) -> Result<Response, Error>

Download raw bytes via GET /bytes/{ref} and return the raw reqwest::Response for streaming. The caller drives reading from resp.bytes_stream() or resp.chunk().

Source

pub async fn probe_data( &self, reference: &Reference, ) -> Result<ReferenceInformation, Error>

Probe the size of the data behind a /bytes reference using a HEAD request. Mirrors bee-js Bee.probeData.

Source§

impl FileApi

Source

pub async fn create_feed_manifest( &self, batch_id: &BatchId, owner: &EthAddress, topic: &Topic, ) -> Result<Reference, Error>

POST /feeds/{owner}/{topic} — create a feed manifest for the given pair. Returns the manifest reference.

Source

pub async fn get_feed_lookup( &self, owner: &EthAddress, topic: &Topic, ) -> Result<Reference, Error>

GET /feeds/{owner}/{topic} — return the latest feed lookup.

Source

pub async fn fetch_latest_feed_update( &self, owner: &EthAddress, topic: &Topic, ) -> Result<FeedUpdate, Error>

Fetch the most recent feed update.

The body is the wrapped chunk payload; the swarm-feed-index and swarm-feed-index-next headers carry the indexes as 8-byte big-endian hex.

Source

pub async fn find_next_index( &self, owner: &EthAddress, topic: &Topic, ) -> Result<u64, Error>

Return the index where the next feed update should be written. Bee returns 404 / 500 when the feed is empty; this helper translates those to 0.

Source

pub async fn update_feed( &self, batch_id: &BatchId, signer: &PrivateKey, topic: &Topic, data: &[u8], ) -> Result<UploadResult, Error>

Update the feed at the next available index. The chunk payload is BE-uint64(timestamp) || data. Mirrors bee-js updateFeedWithPayload.

Source

pub async fn update_feed_with_reference( &self, batch_id: &BatchId, signer: &PrivateKey, topic: &Topic, reference: &Reference, index: Option<u64>, ) -> Result<UploadResult, Error>

Update the feed to point at reference. The chunk payload is BE-uint64(timestamp) || reference(32 or 64). If index is None, FileApi::find_next_index is called.

Source

pub async fn update_feed_with_index( &self, batch_id: &BatchId, signer: &PrivateKey, topic: &Topic, index: u64, data: &[u8], ) -> Result<UploadResult, Error>

Update the feed at a specific index.

The chunk identifier is keccak256(topic || BE-uint64(index)); the payload is BE-uint64(now_unix_seconds) || data. The chunk is signed via SOC and uploaded to /soc/{owner}/{id}.

Source

pub async fn is_feed_retrievable( &self, owner: &EthAddress, topic: &Topic, index: Option<u64>, opts: Option<&DownloadOptions>, ) -> Result<bool, Error>

True iff the feed currently resolves on the network. If index is None, only the latest update is checked. If index is Some(i), every chunk from 0 through i is checked via FileApi::are_all_sequential_feeds_update_retrievable.

Source

pub async fn are_all_sequential_feeds_update_retrievable( &self, owner: &EthAddress, topic: &Topic, index: u64, opts: Option<&DownloadOptions>, ) -> Result<bool, Error>

True iff every feed-update chunk from 0 through index (inclusive) is currently retrievable. Used to validate that a feed can be replayed from its origin.

Source

pub fn make_feed_reader(&self, owner: EthAddress, topic: Topic) -> FeedReader

Construct a FeedReader bound to (owner, topic). Mirrors bee-js Bee.makeFeedReader.

Source

pub fn make_feed_writer( &self, signer: PrivateKey, topic: Topic, ) -> Result<FeedWriter, Error>

Construct a FeedWriter bound to (signer, topic). Owner is derived from signer.public_key().address(). Mirrors bee-js Bee.makeFeedWriter.

Source§

impl FileApi

Source

pub async fn upload_soc( &self, batch_id: &BatchId, owner: &EthAddress, identifier: &Identifier, signature: &Signature, data: impl Into<Bytes>, opts: Option<&UploadOptions>, ) -> Result<UploadResult, Error>

Upload a Single Owner Chunk to POST /soc/{owner}/{id}?sig=…. data must be the SOC body in wire form: span (8) || payload. Mirrors bee-go (*Service).UploadSOC.

Source

pub fn make_soc_reader(&self, owner: EthAddress) -> SocReader

Construct a SocReader for the given owner.

Source

pub fn make_soc_writer(&self, signer: PrivateKey) -> Result<SocWriter, Error>

Construct a SocWriter for the given signer. Owner is derived from signer.public_key().address().

Source§

impl FileApi

Source

pub async fn save_manifest_recursively( &self, node: &mut MantarayNode, batch_id: &BatchId, opts: Option<&UploadOptions>, ) -> Result<UploadResult, Error>

Persist a MantarayNode tree recursively, depth-first.

Mirrors bee-js MantarayNode.saveRecursively — each child is uploaded first (so its self_address is populated), then the node itself is marshaled and uploaded via /bytes. The resulting reference is stored on the node’s self_address and returned to the caller.

Source

pub async fn stream_directory( &self, batch_id: &BatchId, dir: impl AsRef<Path>, opts: Option<&CollectionUploadOptions>, on_progress: Option<OnStreamProgressFn>, ) -> Result<UploadResult, Error>

Stream a directory upload chunk-by-chunk.

For each regular file under dir, content-addresses it via FileChunker, uploads the resulting chunks via POST /chunks with up to N=64 concurrent in-flight uploads, then assembles a Mantaray manifest with one fork per file (path → content-addressed root). Finally calls FileApi::save_manifest_recursively to persist the manifest and returns its reference.

Mirrors bee-js Bee.streamDirectory. The on_progress callback fires once per uploaded chunk with (processed, total) counts.

Differences from bee-js:

  • File contents are read fully into memory before being fed to the chunker. True file-streaming (read → seal → upload as a pipeline) can be added later if a real use case lands.
  • Per-file metadata (Content-Type / Filename) is not yet set on the Mantaray fork — bee-js sets Content-Type from the file extension, but bee-rs leaves manifests metadata-free for now; see Self::upload_collection for the tar-based path that lets Bee infer types server-side.
Source

pub async fn stream_collection_entries( &self, batch_id: &BatchId, entries: &[CollectionEntry], opts: Option<&CollectionUploadOptions>, on_progress: Option<OnStreamProgressFn>, ) -> Result<UploadResult, Error>

Same as Self::stream_directory but takes pre-built in-memory entries instead of walking the filesystem.

Trait Implementations§

Source§

impl Clone for FileApi

Source§

fn clone(&self) -> FileApi

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileApi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more