pub struct Batch<C>(/* private fields */)
where
C: Connector<RpcService>;
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>,
impl<C> Batch<C>where
C: Connector<RpcService>,
sourcepub async fn add_bytes(&self, bytes: impl Into<Bytes>) -> Result<TempTag>
pub async fn add_bytes(&self, bytes: impl Into<Bytes>) -> Result<TempTag>
Write a blob by passing bytes.
sourcepub async fn add_file(&self, path: PathBuf) -> Result<(TempTag, u64)>
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
.
sourcepub async fn add_dir(&self, root: PathBuf) -> Result<TempTag>
pub async fn add_dir(&self, root: PathBuf) -> Result<TempTag>
Add a directory as a hashseq in iroh collection format
sourcepub async fn add_reader(
&self,
reader: impl AsyncRead + Unpin + Send + 'static
) -> Result<TempTag>
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
.
sourcepub async fn add_stream(
&self,
input: impl Stream<Item = Result<Bytes>> + Send + Unpin + 'static
) -> Result<TempTag>
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.
sourcepub async fn temp_tag(&self, content: HashAndFormat) -> Result<TempTag>
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 TempTag
s automatically.
TempTag
s allow you to protect some data from deletion while a download is ongoing,
even if you don’t want to protect it permanently.
sourcepub async fn add_reader_with_opts(
&self,
reader: impl AsyncRead + Unpin + Send + 'static,
opts: AddReaderOpts
) -> Result<TempTag>
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.
sourcepub async fn add_bytes_with_opts(
&self,
bytes: impl Into<Bytes>,
format: BlobFormat
) -> Result<TempTag>
pub async fn add_bytes_with_opts( &self, bytes: impl Into<Bytes>, format: BlobFormat ) -> Result<TempTag>
Write a blob by passing bytes.
sourcepub async fn add_file_with_opts(
&self,
path: PathBuf,
opts: AddFileOpts
) -> Result<(TempTag, u64)>
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.
sourcepub async fn add_dir_with_opts(
&self,
root: PathBuf,
opts: AddDirOpts
) -> Result<TempTag>
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.
sourcepub async fn add_stream_with_opts(
&self,
input: impl Stream<Item = Result<Bytes>> + Send + Unpin + 'static,
format: BlobFormat
) -> Result<TempTag>
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
.
sourcepub async fn add_collection(&self, collection: Collection) -> Result<TempTag>
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.
sourcepub async fn add_blob_seq(
&self,
iter: impl Iterator<Item = Bytes>
) -> Result<TempTag>
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.
sourcepub async fn persist(&self, tt: TempTag) -> Result<Tag>
pub async fn persist(&self, tt: TempTag) -> Result<Tag>
Upgrades a temp tag to a persistent tag.
sourcepub async fn persist_to(&self, tt: TempTag, tag: Tag) -> Result<()>
pub async fn persist_to(&self, tt: TempTag, tag: Tag) -> Result<()>
Upgrades a temp tag to a persistent tag with a specific name.
sourcepub async fn persist_with_opts(
&self,
tt: TempTag,
opts: SetTagOption
) -> Result<Tag>
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.