Skip to content

Commit

Permalink
Fixed segmentation capabilities in new ZffWriter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ph0llux committed Dec 29, 2024
1 parent 3f10354 commit 19d721c
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 110 deletions.
14 changes: 14 additions & 0 deletions src/lib/header/chunk_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ pub enum ChunkMapType {
DeduplicationMap = 5,
}

impl fmt::Display for ChunkMapType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let value = match self {
ChunkMapType::OffsetMap => "OffsetMap",
ChunkMapType::SizeMap => "SizeMap",
ChunkMapType::FlagsMap => "FlagsMap",
ChunkMapType::XxHashMap => "XxHashMap",
ChunkMapType::SamebytesMap => "SamebytesMap",
ChunkMapType::DeduplicationMap => "DeduplicationMap",
};
write!(f, "{value}")
}
}

/// The ChunkMaps struct contains all chunk maps.
#[derive(Debug,Clone,PartialEq,Eq,Default)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
Expand Down
14 changes: 10 additions & 4 deletions src/lib/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::os::windows::fs::MetadataExt;
use crate::{
Result,
header::{FileHeader, FileType, CompressionHeader, ObjectHeader, DeduplicationChunkMap, MetadataExtendedValue},
footer::MainFooter,
footer::{MainFooter, SegmentFooter},
ZffError,
ZffErrorKind,
ObjectEncoder,
Expand All @@ -53,24 +53,30 @@ use log::{info, warn, debug};

#[derive(Debug, Clone)]
struct ZffExtenderParameter {
pub main_footer: MainFooter,
pub current_segment: PathBuf,
pub next_object_no: u64,
pub initial_chunk_number: u64,
pub segment_number: u64,
pub segment_footer: SegmentFooter,
pub main_footer: MainFooter,
}

impl ZffExtenderParameter {
fn with_data(
main_footer: MainFooter,
current_segment: PathBuf,
next_object_no: u64,
initial_chunk_number: u64,
segment_number: u64,
segment_footer: SegmentFooter,
main_footer: MainFooter,
) -> Self {
Self {
main_footer,
current_segment,
next_object_no,
initial_chunk_number,
segment_number,
segment_footer,
main_footer,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/io/zffreader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,12 +1115,11 @@ fn initialize_unencrypted_object_reader<R: Read + Seek>(
) -> Result<ZffObjectReader> {
#[cfg(feature = "log")]
debug!("Initialize unencrypted object reader for object {}", obj_number);

let header = match segments.get_mut(&header_segment_no) {
None => return Err(ZffError::new(ZffErrorKind::MissingSegment, header_segment_no.to_string())),
Some(segment) => segment.read_object_header(obj_number)?,
};

let footer = match segments.get_mut(&footer_segment_no) {
None => return Err(ZffError::new(ZffErrorKind::MissingSegment, header_segment_no.to_string())),
Some(segment) => segment.read_object_footer(obj_number)?,
Expand Down
Loading

0 comments on commit 19d721c

Please sign in to comment.