-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export all headers from MultiGzDecoder #348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,7 @@ pub struct GzDecoder<R> { | |
state: GzState, | ||
reader: CrcReader<deflate::bufread::DeflateDecoder<R>>, | ||
multi: bool, | ||
headers: Vec<GzHeader>, | ||
} | ||
|
||
#[derive(Debug)] | ||
|
@@ -240,6 +241,7 @@ impl<R: BufRead> GzDecoder<R> { | |
state, | ||
reader: CrcReader::new(deflate::bufread::DeflateDecoder::new(r)), | ||
multi: false, | ||
headers: Vec::new(), | ||
} | ||
} | ||
|
||
|
@@ -284,6 +286,7 @@ impl<R: BufRead> Read for GzDecoder<R> { | |
state, | ||
reader, | ||
multi, | ||
headers, | ||
} = self; | ||
|
||
loop { | ||
|
@@ -366,9 +369,10 @@ impl<R: BufRead> Read for GzDecoder<R> { | |
return Err(err); | ||
} | ||
}; | ||
headers.push(header); | ||
|
||
if is_eof { | ||
GzState::End(Some(header)) | ||
GzState::End(None) | ||
} else { | ||
reader.reset(); | ||
reader.get_mut().reset_data(); | ||
|
@@ -449,9 +453,13 @@ impl<R: BufRead> MultiGzDecoder<R> { | |
} | ||
|
||
impl<R> MultiGzDecoder<R> { | ||
/// Returns the current header associated with this stream, if it's valid | ||
pub fn header(&self) -> Option<&GzHeader> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is no need to make this a breaking change by removing the single-header access method. It can live side-by-side with the |
||
self.0.header() | ||
/// Returns the headers processed so far | ||
pub fn headers(&self) -> Vec<&GzHeader> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be allocation-free by returning self.0.headers.iter().chain(self.0.header()) |
||
let mut hdrs: Vec<&GzHeader> = self.0.headers.iter().collect(); | ||
if let Some(hdr) = &self.0.header() { | ||
hdrs.push(hdr) | ||
} | ||
hdrs | ||
} | ||
|
||
/// Acquires a reference to the underlying reader. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,9 +237,9 @@ impl<R: Read> MultiGzDecoder<R> { | |
} | ||
|
||
impl<R> MultiGzDecoder<R> { | ||
/// Returns the current header associated with this stream, if it's valid. | ||
pub fn header(&self) -> Option<&GzHeader> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is no need to make this a breaking change by removing the single-header access method. It can live side-by-side with the |
||
self.inner.header() | ||
/// Returns the headers processed so far | ||
pub fn headers(&self) -> Vec<&GzHeader> { | ||
self.inner.headers() | ||
} | ||
|
||
/// Acquires a reference to the underlying reader. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if performance wouldn't be an issue, these headers contain a few allocations themselves and I can imagine that archives with millions of members would now see a problem with memory consumption where previously they would not have an issue.
In order to prevent regression in that regard, I think this feature must be opt-in, controllable from the
MutliGzDecoder
which already sets themulti
flag.