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 implementsReadAtfor 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>
impl<R: ReadAt> ZffReader<R>
Sourcepub fn with_reader(reader_vec: Vec<R>) -> Result<Self>
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.
Sourcepub fn list_objects(&self) -> Result<BTreeMap<u64, ObjectType>>
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)
Sourcepub fn list_decrypted_objects(&self) -> BTreeMap<u64, ObjectType>
pub fn list_decrypted_objects(&self) -> BTreeMap<u64, ObjectType>
Same as list_objects, but ignores encrypted objects
Sourcepub fn set_active_object(&mut self, object_number: u64) -> Result<()>
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.
Sourcepub fn preinitialize_virtual_object_filemaps(&mut self) -> Result<()>
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.
Sourcepub fn set_active_file(&mut self, filenumber: u64) -> Result<()>
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.
Sourcepub fn current_fileheader(&self) -> Result<FileHeader>
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.
Sourcepub fn current_filemetadata(&self) -> Result<&FileMetadata>
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.
Sourcepub fn filemetadata(
&self,
object_number: u64,
file_number: u64,
) -> Result<&FileMetadata>
pub fn filemetadata( &self, object_number: u64, file_number: u64, ) -> Result<&FileMetadata>
Returns the FileMetadata for the given file(number) from given object(number).
Sourcepub fn initialize_object(&mut self, object_number: u64) -> Result<()>
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.
Sourcepub fn initialize_objects_all(&mut self) -> Result<()>
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.
Sourcepub fn number_of_chunks(&self) -> u64
pub fn number_of_chunks(&self) -> u64
Lists the number of chunks of this zff container.
Sourcepub fn get_xxhashmaps_unencrypted(&self) -> Result<BTreeMap<u64, u64>>
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)
Sourcepub fn chunk_data(&self, chunk_no: u64) -> Result<Vec<u8>>
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.
Sourcepub fn decrypt_object<P: AsRef<[u8]>>(
&mut self,
object_number: u64,
decryption_password: P,
) -> Result<ObjectType>
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)
Sourcepub fn set_preload_chunkmaps_mode_in_memory(&mut self) -> Result<()>
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.
Sourcepub fn set_preload_chunkmap_mode_redb(&mut self, db: Database) -> Result<()>
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.
Sourcepub fn preload_chunk_header_map_per_object(
&mut self,
object_number: u64,
) -> Result<()>
pub fn preload_chunk_header_map_per_object( &mut self, object_number: u64, ) -> Result<()>
Preloads all chunk header maps for the specific object.
Sourcepub fn preload_chunk_header_map_full(&mut self) -> Result<()>
pub fn preload_chunk_header_map_full(&mut self) -> Result<()>
Preloads all chunk header maps for all objects.
Sourcepub fn preload_chunk_samebytes_map_per_object(
&mut self,
object_number: u64,
) -> Result<()>
pub fn preload_chunk_samebytes_map_per_object( &mut self, object_number: u64, ) -> Result<()>
Preloads all samebyte chunk maps for the specific object.
Sourcepub fn preload_chunk_samebytes_map_full(&mut self) -> Result<()>
pub fn preload_chunk_samebytes_map_full(&mut self) -> Result<()>
Preloads all samebyte chunks
Sourcepub fn preload_chunk_deduplication_map_per_object(
&mut self,
object_number: u64,
) -> Result<()>
pub fn preload_chunk_deduplication_map_per_object( &mut self, object_number: u64, ) -> Result<()>
Preloads all deduplication chunk maps for the specific object.
Sourcepub fn preload_chunk_deduplication_map_full(&mut self) -> Result<()>
pub fn preload_chunk_deduplication_map_full(&mut self) -> Result<()>
Preloads all deduplication chunks
Sourcepub fn active_object_header_ref(&self) -> Result<&ObjectHeader>
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.
Trait Implementations§
Source§impl<R: ReadAt> Read for ZffReader<R>
impl<R: ReadAt> Read for ZffReader<R>
Source§fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl<R: ReadAt> Seek for ZffReader<R>
impl<R: ReadAt> Seek for ZffReader<R>
Source§fn seek(&mut self, seek_from: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, seek_from: SeekFrom) -> Result<u64, Error>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Auto Trait Implementations§
impl<R> !RefUnwindSafe for ZffReader<R>
impl<R> !UnwindSafe for ZffReader<R>
impl<R> Freeze for ZffReader<R>
impl<R> Send for ZffReader<R>
impl<R> Sync for ZffReader<R>
impl<R> Unpin for ZffReader<R>
impl<R> UnsafeUnpin for ZffReader<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R> ReadBytesExt for R
impl<R> ReadBytesExt for R
Source§fn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
Source§fn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
Source§fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
Source§fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
Source§fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Source§fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Source§fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Source§fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Source§fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
Source§fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
Source§fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
Source§fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
Source§fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
Source§fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
Source§fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
Source§fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
please use read_f32_into instead