fastcdc::v2020

Struct AsyncStreamCDC

Source
pub struct AsyncStreamCDC<R> { /* private fields */ }
Expand description

An async-streamable version of the FastCDC chunker implementation from 2020 with streaming support.

Use new to construct an instance, and then as_stream to produce an async Stream of the chunks.

Both futures and tokio-based AsyncRead inputs are supported via feature flags. But, if necessary you can also use the async_compat crate to adapt your inputs as circumstances may require.

Note that this struct allocates a Vec<u8> of max_size bytes to act as a buffer when reading from the source and finding chunk boundaries.


async fn run() {
    let source = std::fs::read("test/fixtures/SekienAkashita.jpg").unwrap();
    let mut chunker = AsyncStreamCDC::new(source.as_ref(), 4096, 16384, 65535);
    let stream = chunker.as_stream();

    let chunks = stream.collect::<Vec<_>>().await;

    for result in chunks {
        let chunk = result.unwrap();
        println!("offset={} length={}", chunk.offset, chunk.length);
    }
}

Implementations§

Source§

impl<R: AsyncRead + Unpin> AsyncStreamCDC<R>

Source

pub fn new(source: R, min_size: u32, avg_size: u32, max_size: u32) -> Self

Construct a StreamCDC that will process bytes from the given source.

Uses chunk size normalization level 1 by default.

Source

pub fn with_level( source: R, min_size: u32, avg_size: u32, max_size: u32, level: Normalization, ) -> Self

Create a new StreamCDC with the given normalization level.

Source

pub fn as_stream(&mut self) -> impl Stream<Item = Result<ChunkData, Error>> + '_

Auto Trait Implementations§

§

impl<R> Freeze for AsyncStreamCDC<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for AsyncStreamCDC<R>
where R: RefUnwindSafe,

§

impl<R> Send for AsyncStreamCDC<R>
where R: Send,

§

impl<R> Sync for AsyncStreamCDC<R>
where R: Sync,

§

impl<R> Unpin for AsyncStreamCDC<R>
where R: Unpin,

§

impl<R> UnwindSafe for AsyncStreamCDC<R>
where R: UnwindSafe,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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