Skip to main content

ZffReader

Struct ZffReader 

Source
pub struct ZffReader<R: ReadAt> { /* private fields */ }
Expand description

The ZffReader can be used to read the data of a zff container in a proper way.
It implements std::io::Read and std::io::Seek to ensure a wide range of possible use.

§Example

use zff::io::zffreader::ZffReader;
use std::fs::File;
use std::io::Read;

let segment_files = vec!["zff_segment.z01", "zff_segment.z02", "zff_segment.z03"];
let mut files = Vec::new();
for segment in segment_files {
    files.push(File::open(segment).unwrap());
}

let mut zffreader = ZffReader::with_reader(files).unwrap();
// list available object numbers.
println!("{:?}", zffreader.list_objects().unwrap().keys());
// let us assume object 1 is a physical object.
zffreader.initialize_object(1).unwrap();
zffreader.set_active_object(1).unwrap();

let mut buffer = vec![0u8; 32000];
let _  = zffreader.read_exact(&mut buffer).unwrap();

Main reader type for zff containers.

The ZffReader provides functionality to read and access data from zff containers. It supports reading physical, logical, virtual, and encrypted objects.

§Type Parameters

  • R: The type of reader that implements ReadAt for random access reading.

§Examples

use zff::io::zffreader::ZffReader;
use std::fs::File;

// Create a reader from a vector of segment files
let reader = ZffReader::with_reader(vec![File::open("segment.z01").unwrap()]).unwrap();

Implementations§

Source§

impl<R: ReadAt> ZffReader<R>

Source

pub fn with_reader(reader_vec: Vec<R>) -> Result<Self>

This method will initialize the ZffReader in general. This method will identify the appropriate SegmentHeader, SegmentFooter and MainFooter.
This method will not initizalize the objects itself! This has to be done by using the initialize_object() or initialize_objects_all() methods.

Source

pub fn list_objects(&self) -> Result<BTreeMap<u64, ObjectType>>

Lists all objects which are inside the zff container (even if they are uninitialized). Returns a BTreeMap, which contains the appropriate object number and the object type.

§Error

Fails if

  • a segment is missing which should contain the appropriate object header
  • there is an error while reading the object header
  • there is a decoding error (e.g. corrupted segment)
Source

pub fn list_decrypted_objects(&self) -> BTreeMap<u64, ObjectType>

Same as list_objects, but ignores encrypted objects

Source

pub fn set_active_object(&mut self, object_number: u64) -> Result<()>

Sets an appropriate object as active to read or seek from this object.

§Error

This method fails, if the appropriate object number not exists in this zff container.

Source

pub fn preinitialize_virtual_object_filemaps(&mut self) -> Result<()>

Pre-initializes all filemaps of the active virtual object. This can speed up later file access, but increases memory usage.

If the active object is not a virtual object, this method does nothing.

§Error

Fails if the filemaps of the active virtual object cannot be initialized.

Source

pub fn set_active_file(&mut self, filenumber: u64) -> Result<()>

Sets an appropriate file as active to read or seek from this object.

§Error

This method fails, if the appropriate object type is not “logical” or “virtual logical”, or if no file for the appropriate file number exists. Will also fail, if no object was activated by using the set_active_object() method.

Source

pub fn current_fileheader(&self) -> Result<FileHeader>

Returns the FileHeader of the appropriate active file.

§Error

May fail if

  • the active object is not a “logical” object.
  • the active file number was not set.
  • no object was set as active.
Source

pub fn current_filemetadata(&self) -> Result<&FileMetadata>

Returns the FileMetadata of the appropriate active file.

§Error

May fail if

  • the active object is not a “logical” object.
  • the active file number was not set.
  • no object was set as active.
Source

pub fn filemetadata( &self, object_number: u64, file_number: u64, ) -> Result<&FileMetadata>

Returns the FileMetadata for the given file(number) from given object(number).

Source

pub fn initialize_object(&mut self, object_number: u64) -> Result<()>

Will initialize the appropriate object.

§Error

May fail due to various conditions, e.g. corrupted or missing segments.

Source

pub fn initialize_objects_all(&mut self) -> Result<()>

Same as initialize_object(), but will initialize all objects of this zff container.

§Error

May fail due to various conditions, e.g. corrupted or missing segments.

Source

pub fn number_of_chunks(&self) -> u64

Lists the number of chunks of this zff container.

Source

pub fn get_xxhashmaps_unencrypted(&self) -> Result<BTreeMap<u64, u64>>

Returns a list of all xxhashes (of all unencrypted objects) as BTreeMap<u64, u64> (chunk_no / appropriate xxhash)

Source

pub fn chunk_data(&self, chunk_no: u64) -> Result<Vec<u8>>

Returns the Data of the given chunk no

§Error
  • If the object is encrypted, it will return an error.
  • If the chunk number is out of range, it will return an error.
Source

pub fn decrypt_object<P: AsRef<[u8]>>( &mut self, object_number: u64, decryption_password: P, ) -> Result<ObjectType>

Decrypts an encrypted initialized object (and re-initialize/replaces the appropriate object directly).

§Error

May fail due to various conditions:

  • The appropriate object number does not exist or is uninitialized.
  • The appropriate object is not encrypted.
  • The decryption password is incorrect.
  • The decoding or reading of the data fails (e.g. corrupted or missing segments)
Source

pub fn set_preload_chunkmaps_mode_in_memory(&mut self) -> Result<()>

Defines a new preload chunkmap which will be held in memory, if none exists up to this point. This method will (then) only “initialize” a new preload chunkmap. You have to fill this map by using
methods like self::preloaded_chunkmap() or self::preload_chunkmap_full().
If there is already a preloaded chunkmap, then this method will

  • do nothing, if the existing preloaded chunkmap is an in-memory map.
  • convert the existing preloaded chunkmap to an in-memory chunkmap, if the existing preloaded chunkmap is a redb-based preloaded chunkmap.
Source

pub fn set_preload_chunkmap_mode_redb(&mut self, db: Database) -> Result<()>

Defines a new preload chunkmap which will be cached to a external Redb, if none exists up to this point. This method will (then) only “initialize” a new preload chunkmap. You have to fill this map by using
methods like self::preloaded_chunkmap() or self::preload_chunkmap_full().
If there is already a preloaded chunkmap, then this method will

  • Copy the content of the existing Redb to the new given Redb and use the given Redb as the new one.
  • Initialize a empty Redb and use this.
  • convert the existing preloaded (in-memory) chunkmap to the Redb (copy the content) and use the Redb as the appropriate preloaded chunkmap.
Source

pub fn preload_chunk_header_map_per_object( &mut self, object_number: u64, ) -> Result<()>

Preloads all chunk header maps for the specific object.

Source

pub fn preload_chunk_header_map_full(&mut self) -> Result<()>

Preloads all chunk header maps for all objects.

Source

pub fn preload_chunk_samebytes_map_per_object( &mut self, object_number: u64, ) -> Result<()>

Preloads all samebyte chunk maps for the specific object.

Source

pub fn preload_chunk_samebytes_map_full(&mut self) -> Result<()>

Preloads all samebyte chunks

Source

pub fn preload_chunk_deduplication_map_per_object( &mut self, object_number: u64, ) -> Result<()>

Preloads all deduplication chunk maps for the specific object.

Source

pub fn preload_chunk_deduplication_map_full(&mut self) -> Result<()>

Preloads all deduplication chunks

Source

pub fn active_object_header_ref(&self) -> Result<&ObjectHeader>

Returns a reference to the ObjectHeader of the appropriate active object.

§Error

May fail if

  • no object was set as active.
  • the object was not decrypted.

Returns the ObjectFooter of the appropriate active object.

§Error

May fail if

  • the object does not exist.
  • the object was not decrypted.
Source

pub fn read_at( &self, buf: &mut [u8], object_number: u64, file_number: u64, offset: u64, ) -> Result<usize>

Reads the approrpriate bytes into the buffer (for given objectnumber/filenumber) at given offset.

Source

pub fn read_at_to_end( &self, buf: &mut Vec<u8>, object_number: u64, file_no: u64, offset: u64, ) -> Result<usize>

Same as read_to_end, but starts at the appropriate offset.

Trait Implementations§

Source§

impl<R: Debug + ReadAt> Debug for ZffReader<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: ReadAt> Read for ZffReader<R>

Source§

fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>

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

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

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

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

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

fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self> ⓘ
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self> ⓘ
where Self: Sized,

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

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
where Self: Sized,

🔬This is a nightly-only experimental API. (read_array)
Read and return a fixed array of bytes from this source. Read more
Source§

fn read_le<T>(&mut self) -> Result<T, Error>
where T: FromEndianBytes, Self: Sized,

🔬This is a nightly-only experimental API. (read_le)
Read and return a type (e.g. an integer) in little-endian order. Read more
Source§

fn read_be<T>(&mut self) -> Result<T, Error>
where T: FromEndianBytes, Self: Sized,

🔬This is a nightly-only experimental API. (read_le)
Read and return a type (e.g. an integer) in big-endian order. Read more
Source§

impl<R: ReadAt> Seek for ZffReader<R>

Source§

fn seek(&mut self, seek_from: SeekFrom) -> Result<u64, Error>

Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for ZffReader<R>

§

impl<R> !UnwindSafe for ZffReader<R>

§

impl<R> Freeze for ZffReader<R>
where Arc<ZffReaderGeneralMetadata<R>>: Freeze, HashMap<u64, ZffObjectReader<R>>: Freeze,

§

impl<R> Send for ZffReader<R>
where Arc<ZffReaderGeneralMetadata<R>>: Send, HashMap<u64, ZffObjectReader<R>>: Send,

§

impl<R> Sync for ZffReader<R>
where Arc<ZffReaderGeneralMetadata<R>>: Sync, HashMap<u64, ZffObjectReader<R>>: Sync,

§

impl<R> Unpin for ZffReader<R>
where Arc<ZffReaderGeneralMetadata<R>>: Unpin, HashMap<u64, ZffObjectReader<R>>: Unpin,

§

impl<R> UnsafeUnpin for ZffReader<R>
where Arc<ZffReaderGeneralMetadata<R>>: UnsafeUnpin, HashMap<u64, ZffObjectReader<R>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R> ReadBytesExt for R
where R: Read + ?Sized,

Source§

fn read_u8(&mut self) -> Result<u8, Error>

Reads an unsigned 8 bit integer from the underlying reader. Read more
Source§

fn read_i8(&mut self) -> Result<i8, Error>

Reads a signed 8 bit integer from the underlying reader. Read more
Source§

fn read_u16<T>(&mut self) -> Result<u16, Error>
where T: ByteOrder,

Reads an unsigned 16 bit integer from the underlying reader. Read more
Source§

fn read_i16<T>(&mut self) -> Result<i16, Error>
where T: ByteOrder,

Reads a signed 16 bit integer from the underlying reader. Read more
Source§

fn read_u24<T>(&mut self) -> Result<u32, Error>
where T: ByteOrder,

Reads an unsigned 24 bit integer from the underlying reader. Read more
Source§

fn read_i24<T>(&mut self) -> Result<i32, Error>
where T: ByteOrder,

Reads a signed 24 bit integer from the underlying reader. Read more
Source§

fn read_u32<T>(&mut self) -> Result<u32, Error>
where T: ByteOrder,

Reads an unsigned 32 bit integer from the underlying reader. Read more
Source§

fn read_i32<T>(&mut self) -> Result<i32, Error>
where T: ByteOrder,

Reads a signed 32 bit integer from the underlying reader. Read more
Source§

fn read_u48<T>(&mut self) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned 48 bit integer from the underlying reader. Read more
Source§

fn read_i48<T>(&mut self) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed 48 bit integer from the underlying reader. Read more
Source§

fn read_u64<T>(&mut self) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned 64 bit integer from the underlying reader. Read more
Source§

fn read_i64<T>(&mut self) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed 64 bit integer from the underlying reader. Read more
Source§

fn read_u128<T>(&mut self) -> Result<u128, Error>
where T: ByteOrder,

Reads an unsigned 128 bit integer from the underlying reader. Read more
Source§

fn read_i128<T>(&mut self) -> Result<i128, Error>
where T: ByteOrder,

Reads a signed 128 bit integer from the underlying reader. Read more
Source§

fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned n-bytes integer from the underlying reader. Read more
Source§

fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed n-bytes integer from the underlying reader. Read more
Source§

fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>
where T: ByteOrder,

Reads an unsigned n-bytes integer from the underlying reader.
Source§

fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>
where T: ByteOrder,

Reads a signed n-bytes integer from the underlying reader.
Source§

fn read_f32<T>(&mut self) -> Result<f32, Error>
where T: ByteOrder,

Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader. Read more
Source§

fn read_f64<T>(&mut self) -> Result<f64, Error>
where T: ByteOrder,

Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader. Read more
Source§

fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 16 bit integers from the underlying reader. Read more
Source§

fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 32 bit integers from the underlying reader. Read more
Source§

fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 64 bit integers from the underlying reader. Read more
Source§

fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 128 bit integers from the underlying reader. Read more
Source§

fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>

Reads a sequence of signed 8 bit integers from the underlying reader. Read more
Source§

fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 16 bit integers from the underlying reader. Read more
Source§

fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 32 bit integers from the underlying reader. Read more
Source§

fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 64 bit integers from the underlying reader. Read more
Source§

fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 128 bit integers from the underlying reader. Read more
Source§

fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader. Read more
Source§

fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>
where T: ByteOrder,

👎Deprecated since 1.2.0:

please use read_f32_into instead

DEPRECATED. Read more
Source§

fn read_f64_into<T>(&mut self, dst: &mut [f64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more
Source§

fn read_f64_into_unchecked<T>(&mut self, dst: &mut [f64]) -> Result<(), Error>
where T: ByteOrder,

👎Deprecated since 1.2.0:

please use read_f64_into instead

DEPRECATED. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V