[−][src]Struct bao::encode::SliceExtractor
An incremental slice extractor, which reads encoded bytes and produces a slice.
SliceExtractor
supports reading both the combined and outboard encoding, depending on which
constructor you use. Though to be clear, there's no such thing as an "outboard slice" per se.
Slices always include subtree hashes inline with the content, as a combined encoding does.
Note that slices always split the encoding at chunk boundaries. Bao's chunk size is currently
4096 bytes, so using slice_start
and slice_len
arguments that are a multiple that avoids
wasting space. Also, slicing when there's less than a full chunk of input is pointless.
Extracting a slice doesn't re-hash any of the bytes. As a result, it's fast compared to
decoding. You can quickly convert an outboard encoding to a combined encoding by "extracting" a
slice with a slice_start
of zero and a slice_len
equal to the original input length.
See the decode
module for decoding slices.
Example
use std::io::prelude::*; let input = vec![0; 1_000_000]; let (encoded, hash) = bao::encode::encode(&input); // These parameters are multiples of the chunk size, which avoids unnecessary overhead. let slice_start = 65536; let slice_len = 8192; let encoded_cursor = std::io::Cursor::new(&encoded); let mut extractor = bao::encode::SliceExtractor::new(encoded_cursor, slice_start, slice_len); let mut slice = Vec::new(); extractor.read_to_end(&mut slice)?; // The slice includes some overhead to store the necessary subtree hashes, but it's not much. assert_eq!(8712, slice.len());
Methods
impl<T: Read + Seek> SliceExtractor<T, T>
[src]
pub fn new(input: T, slice_start: u64, slice_len: u64) -> Self
[src]
Create a new SliceExtractor
to read from a combined encoding. Note that slice_start
and
slice_len
are with respect to the content of the encoding, that is, the original
input bytes. This corresponds to bao slice slice_start slice_len
.
impl<T: Read + Seek, O: Read + Seek> SliceExtractor<T, O>
[src]
pub fn new_outboard(
input: T,
outboard: O,
slice_start: u64,
slice_len: u64
) -> Self
[src]
input: T,
outboard: O,
slice_start: u64,
slice_len: u64
) -> Self
Create a new SliceExtractor
to read from an unmodified input file and an outboard
encoding of that same file (see Encoder::new_outboard
). As with SliceExtractor::new
,
slice_start
and slice_len
are with respect to the content of the encoding, that is,
the original input bytes. This corresponds to bao slice slice_start slice_len --outboard
.
Trait Implementations
impl<T: Read + Seek, O: Read + Seek> Read for SliceExtractor<T, O>
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
Like read
, except that it reads into a slice of buffers. Read more
unsafe fn initializer(&self) -> Initializer
[src]
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
Read all bytes until EOF in this source, appending them to buf
. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0[src]
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Creates an adaptor which will read at most limit
bytes from it. Read more
Auto Trait Implementations
impl<T, O> Send for SliceExtractor<T, O> where
O: Send,
T: Send,
O: Send,
T: Send,
impl<T, O> Unpin for SliceExtractor<T, O> where
O: Unpin,
T: Unpin,
O: Unpin,
T: Unpin,
impl<T, O> Sync for SliceExtractor<T, O> where
O: Sync,
T: Sync,
O: Sync,
T: Sync,
impl<T, O> RefUnwindSafe for SliceExtractor<T, O> where
O: RefUnwindSafe,
T: RefUnwindSafe,
O: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, O> UnwindSafe for SliceExtractor<T, O> where
O: UnwindSafe,
T: UnwindSafe,
O: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,