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

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. The BLAKE3 chunk size is 1024 bytes, so using slice_start and slice_len values that are an even multiple of 1024 avoids wasting space.

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.
assert_eq!(9096, slice.len());

Implementations

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.

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.

Return the underlying readers. The second reader is Some if and only if this SliceExtractor was created with new_outboard.

Trait Implementations

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

Like read, except that it reads into a slice of buffers. Read more

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

Determines if this Reader has an efficient read_vectored implementation. 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

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

Pull some bytes from this source into the specified buffer. Read more

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

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

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

Creates an adapter which will read at most limit bytes from it. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.