Struct bao::encode::SliceExtractor

source ·
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. 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());

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 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§

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 cursor. 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 alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Reads an unsigned 8 bit integer from the underlying reader. Read more
Reads a signed 8 bit integer from the underlying reader. Read more
Reads an unsigned 16 bit integer from the underlying reader. Read more
Reads a signed 16 bit integer from the underlying reader. Read more
Reads an unsigned 24 bit integer from the underlying reader. Read more
Reads a signed 24 bit integer from the underlying reader. Read more
Reads an unsigned 32 bit integer from the underlying reader. Read more
Reads a signed 32 bit integer from the underlying reader. Read more
Reads an unsigned 48 bit integer from the underlying reader. Read more
Reads a signed 48 bit integer from the underlying reader. Read more
Reads an unsigned 64 bit integer from the underlying reader. Read more
Reads a signed 64 bit integer from the underlying reader. Read more
Reads an unsigned 128 bit integer from the underlying reader. Read more
Reads a signed 128 bit integer from the underlying reader. Read more
Reads an unsigned n-bytes integer from the underlying reader. Read more
Reads a signed n-bytes integer from the underlying reader. Read more
Reads an unsigned n-bytes integer from the underlying reader.
Reads a signed n-bytes integer from the underlying reader.
Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader. Read more
Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader. Read more
Reads a sequence of unsigned 16 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 32 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 64 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 128 bit integers from the underlying reader. Read more
Reads a sequence of signed 8 bit integers from the underlying reader. Read more
Reads a sequence of signed 16 bit integers from the underlying reader. Read more
Reads a sequence of signed 32 bit integers from the underlying reader. Read more
Reads a sequence of signed 64 bit integers from the underlying reader. Read more
Reads a sequence of signed 128 bit integers from the underlying reader. Read more
Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader. Read more
👎Deprecated since 1.2.0: please use read_f32_into instead
DEPRECATED. Read more
Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more
👎Deprecated since 1.2.0: please use read_f64_into instead
DEPRECATED. Read more
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.