Struct bao::encode::SliceExtractor[][src]

pub struct SliceExtractor<T: Read + Seek, O: Read + Seek> { /* fields omitted */ }

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) = bao::encode::encode_to_vec(&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]

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]

Create a new SliceExtractor to read from an unmodified input file and an outboard encoding of that same file (see Writer::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]

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

Creates a "by reference" adaptor for this instance of Read. Read more

Transforms this Read instance to an [Iterator] over its bytes. Read more

Deprecated since 1.27.0

: Use str::from_utf8 instead: https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples

🔬 This is a nightly-only experimental API. (io)

the semantics of a partial read/write of where errors happen is currently unclear and may change

Transforms this Read instance to an [Iterator] over [char]s. Read more

Creates an adaptor which will chain this stream with another. Read more

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

impl<T, O> Sync for SliceExtractor<T, O> where
    O: Sync,
    T: Sync