Skip to content

Commit 2e9247a

Browse files
committed
feat(decompression-plz): added PartialDecompressError to hold if the extra is raw in case of partial decompression
1 parent 80ca83a commit 2e9247a

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

decompression-plz/src/decompression/dstruct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ mod tests {
491491
partial_body,
492492
header_index,
493493
compression_index,
494+
..
494495
} = e.reason
495496
{
496497
assert_eq!(partial_body, INPUT);

decompression-plz/src/decompression/multi/error.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl MultiDecompressError {
2424
&self.reason
2525
}
2626

27+
pub fn reason_as_mut(&mut self) -> &mut MultiDecompressErrorReason {
28+
&mut self.reason
29+
}
30+
2731
pub fn is_corrupt(&self) -> bool {
2832
matches!(self.reason, MultiDecompressErrorReason::Corrupt)
2933
}
@@ -42,6 +46,7 @@ impl MultiDecompressError {
4246
partial_body,
4347
header_index,
4448
compression_index,
49+
is_extra_raw: false,
4550
};
4651
self.reason = reason;
4752
self
@@ -64,11 +69,22 @@ pub enum MultiDecompressErrorReason {
6469
partial_body: BytesMut,
6570
header_index: usize,
6671
compression_index: usize,
72+
is_extra_raw: bool,
6773
},
6874
}
6975

7076
impl MultiDecompressErrorReason {
7177
pub fn is_partial(&self) -> bool {
7278
matches!(self, MultiDecompressErrorReason::Partial { .. })
7379
}
80+
81+
pub fn set_extra_is_raw(&mut self) {
82+
if let MultiDecompressErrorReason::Partial {
83+
is_extra_raw,
84+
..
85+
} = self
86+
{
87+
*is_extra_raw = true;
88+
}
89+
}
7490
}

decompression-plz/src/decompression/multi/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ where
4343
partial_body: output,
4444
header_index,
4545
compression_index,
46+
is_extra_raw: false,
4647
}
4748
};
4849
return Err(MultiDecompressError::new(reason, e));
@@ -143,6 +144,7 @@ mod tests {
143144
partial_body,
144145
header_index,
145146
compression_index,
147+
..
146148
} = result.reason
147149
{
148150
assert_eq!(header_index, 0);
@@ -174,6 +176,7 @@ mod tests {
174176
partial_body,
175177
header_index,
176178
compression_index,
179+
..
177180
} = result.reason
178181
{
179182
assert_eq!(header_index, 0);
@@ -198,6 +201,7 @@ mod tests {
198201
partial_body,
199202
header_index,
200203
compression_index,
204+
..
201205
} = result.reason
202206
{
203207
assert_eq!(header_index, 1);
@@ -226,6 +230,7 @@ mod tests {
226230
partial_body,
227231
header_index,
228232
compression_index,
233+
..
229234
} = result.reason
230235
{
231236
assert_eq!(header_index, 5);

decompression-plz/src/decompression/state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ impl<'a> DecompressionState<'a> {
165165
main_decompressed,
166166
)
167167
}
168-
Err(e) => return Err(e),
168+
Err(mut e) => {
169+
if e.reason().is_partial() {
170+
e.reason_as_mut().set_extra_is_raw();
171+
}
172+
return Err(e);
173+
}
169174
}
170175
}
171176
DecompressionState::EndMainOnly(_)

decompression-plz/src/state.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ where
140140
ref mut partial_body,
141141
header_index,
142142
compression_index,
143+
is_extra_raw,
143144
} = e.reason
144145
{
145146
decode_struct.body = partial_body.split();
146-
decode_struct.extra_body = None;
147+
if !is_extra_raw {
148+
decode_struct.extra_body = None;
149+
}
147150
for (index, einfo) in encoding_info.iter().rev().enumerate() {
148151
if index > header_index {
149152
decode_struct

0 commit comments

Comments
 (0)