Struct iroh_blobs::rpc::client::blobs::Batch

source ·
pub struct Batch<C>(/* private fields */)
where
    C: Connector<RpcService>;
Available on crate feature rpc only.
Expand description

A batch for write operations.

This serves mostly as a scope for temporary tags.

It is not a transaction, so things in a batch are not atomic. Also, there is no isolation between batches.

Implementations§

source§

impl<C> Batch<C>
where C: Connector<RpcService>,

source

pub async fn add_bytes(&self, bytes: impl Into<Bytes>) -> Result<TempTag>

Write a blob by passing bytes.

source

pub async fn add_file(&self, path: PathBuf) -> Result<(TempTag, u64)>

Import a blob from a filesystem path, using the default options.

For more control, use Self::add_file_with_opts.

source

pub async fn add_dir(&self, root: PathBuf) -> Result<TempTag>

Add a directory as a hashseq in iroh collection format

source

pub async fn add_reader( &self, reader: impl AsyncRead + Unpin + Send + 'static ) -> Result<TempTag>

Write a blob by passing an async reader.

This will consume the stream in 64KB chunks, and use a format of BlobFormat::Raw.

For more options, see Self::add_reader_with_opts.

source

pub async fn add_stream( &self, input: impl Stream<Item = Result<Bytes>> + Send + Unpin + 'static ) -> Result<TempTag>

Write a blob by passing a stream of bytes.

source

pub async fn temp_tag(&self, content: HashAndFormat) -> Result<TempTag>

Creates a temp tag to protect some content (blob or hashseq) from being deleted.

This is a lower-level API. The other functions in Batch already create TempTags automatically.

TempTags allow you to protect some data from deletion while a download is ongoing, even if you don’t want to protect it permanently.

source

pub async fn add_reader_with_opts( &self, reader: impl AsyncRead + Unpin + Send + 'static, opts: AddReaderOpts ) -> Result<TempTag>

Write a blob by passing an async reader.

This consumes the stream in chunks using opts.chunk_size. A good default is 64KB.

source

pub async fn add_bytes_with_opts( &self, bytes: impl Into<Bytes>, format: BlobFormat ) -> Result<TempTag>

Write a blob by passing bytes.

source

pub async fn add_file_with_opts( &self, path: PathBuf, opts: AddFileOpts ) -> Result<(TempTag, u64)>

Import a blob from a filesystem path.

path should be an absolute path valid for the file system on which the node runs, which refers to a file.

If you use ImportMode::TryReference, Iroh will assume that the data will not change and will share it in place without copying to the Iroh data directory if appropriate. However, for tiny files, Iroh will copy the data.

If you use ImportMode::Copy, Iroh will always copy the data.

Will return a temp tag for the added blob, as well as the size of the file.

source

pub async fn add_dir_with_opts( &self, root: PathBuf, opts: AddDirOpts ) -> Result<TempTag>

Add a directory as a hashseq in iroh collection format

This can also be used to add a single file as a collection, if wrap is set to WrapOption::Wrap.

However, if you want to add a single file as a raw blob, use add_file instead.

source

pub async fn add_stream_with_opts( &self, input: impl Stream<Item = Result<Bytes>> + Send + Unpin + 'static, format: BlobFormat ) -> Result<TempTag>

Write a blob by passing a stream of bytes.

For convenient interop with common sources of data, this function takes a stream of io::Result<Bytes>. If you have raw bytes, you need to wrap them in io::Result::Ok.

source

pub async fn add_collection(&self, collection: Collection) -> Result<TempTag>

Add a collection.

This is a convenience function that converts the collection into two blobs (the metadata and the hash sequence) and adds them, returning a temp tag for the hash sequence.

Note that this does not guarantee that the data that the collection refers to actually exists. It will just create 2 blobs, the metadata and the hash sequence itself.

source

pub async fn add_blob_seq( &self, iter: impl Iterator<Item = Bytes> ) -> Result<TempTag>

Add a sequence of blobs, where the last is a hash sequence.

It is a common pattern in iroh to have a hash sequence with one or more blobs of metadata, and the remaining blobs being the actual data. E.g. a collection is a hash sequence where the first child is the metadata.

source

pub async fn persist(&self, tt: TempTag) -> Result<Tag>

Upgrades a temp tag to a persistent tag.

source

pub async fn persist_to(&self, tt: TempTag, tag: Tag) -> Result<()>

Upgrades a temp tag to a persistent tag with a specific name.

source

pub async fn persist_with_opts( &self, tt: TempTag, opts: SetTagOption ) -> Result<Tag>

Upgrades a temp tag to a persistent tag with either a specific name or an automatically generated name.

Trait Implementations§

source§

impl<C> Debug for Batch<C>
where C: Connector<RpcService>, Arc<BatchInner<C>>: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> Freeze for Batch<C>

§

impl<C> RefUnwindSafe for Batch<C>
where C: RefUnwindSafe,

§

impl<C> Send for Batch<C>

§

impl<C> Sync for Batch<C>

§

impl<C> Unpin for Batch<C>

§

impl<C> UnwindSafe for Batch<C>
where C: RefUnwindSafe,

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T