Skip to content

Commit 9035072

Browse files
committed
StoredOnlyCompressor feature is here, and we can now access it.
1 parent d1027ab commit 9035072

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ pub enum Compression {
315315
/// the encoder can do, but is meant to emulate the `Best` setting in the `Flate2`
316316
/// library.
317317
Best,
318+
/// Do no compression
319+
None,
318320
#[deprecated(
319321
since = "0.17.6",
320322
note = "use one of the other compression levels instead, such as 'fast'"

src/encoder.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ impl<W: Write> Writer<W> {
694694
let adaptive_method = self.options.adaptive_filter;
695695

696696
let zlib_encoded = match self.info.compression {
697+
Compression::None => self.stored_only_compressor(data, in_len)?,
697698
Compression::Fast => {
698699
let mut compressor = fdeflate::Compressor::new(std::io::Cursor::new(Vec::new()))?;
699700

@@ -724,13 +725,7 @@ impl<W: Write> Writer<W> {
724725
// requested by the user. Doing filtering again would only add performance
725726
// cost for both encoding and subsequent decoding, without improving the
726727
// compression ratio.
727-
let mut compressor =
728-
fdeflate::StoredOnlyCompressor::new(std::io::Cursor::new(Vec::new()))?;
729-
for line in data.chunks(in_len) {
730-
compressor.write_data(&[0])?;
731-
compressor.write_data(line)?;
732-
}
733-
compressor.finish()?.into_inner()
728+
self.stored_only_compressor(data, in_len)?
734729
} else {
735730
compressed
736731
}
@@ -817,6 +812,15 @@ impl<W: Write> Writer<W> {
817812
Ok(())
818813
}
819814

815+
fn stored_only_compressor(&self, data: &[u8], in_len: usize) -> Result<Vec<u8>> {
816+
let mut compressor = fdeflate::StoredOnlyCompressor::new(std::io::Cursor::new(Vec::new()))?;
817+
for line in data.chunks(in_len) {
818+
compressor.write_data(&[0])?;
819+
compressor.write_data(line)?;
820+
}
821+
Ok(compressor.finish()?.into_inner())
822+
}
823+
820824
/// Set the used filter type for the following frames.
821825
///
822826
/// The default filter is [`FilterType::Sub`] which provides a basic prediction algorithm for
@@ -1706,6 +1710,7 @@ impl Compression {
17061710
Compression::Huffman => flate2::Compression::none(),
17071711
#[allow(deprecated)]
17081712
Compression::Rle => flate2::Compression::none(),
1713+
Compression::None => flate2::Compression::none(),
17091714
}
17101715
}
17111716
}

0 commit comments

Comments
 (0)