From 27540301ca1035070bfb8f4d8ab32f06bd5ae2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pi=C3=A8rre?= <77776198+PierreV23@users.noreply.github.com> Date: Sun, 16 Jul 2023 21:06:22 +0200 Subject: [PATCH 1/4] Add functions that allow (de)compress instances --- src/zlib/bufread.rs | 20 ++++++++++++++++++++ src/zlib/read.rs | 34 ++++++++++++++++++++++++++++++++++ src/zlib/write.rs | 15 +++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/zlib/bufread.rs b/src/zlib/bufread.rs index 61d12525..729264ff 100644 --- a/src/zlib/bufread.rs +++ b/src/zlib/bufread.rs @@ -47,6 +47,15 @@ impl ZlibEncoder { data: Compress::new(level, true), } } + + /// Same as `new` but instead of passing a `Compression` instance, + /// a `Compress` instance is passed. + pub fn new_with_compress(r: R, compress: crate::Compress) -> ZlibEncoder { + ZlibEncoder { + obj: r, + data: compress, + } + } } pub fn reset_encoder_data(zlib: &mut ZlibEncoder) { @@ -165,6 +174,17 @@ impl ZlibDecoder { data: Decompress::new(true), } } + + /// Creates a new decoder which will decompress data read from the given + /// stream. + /// + /// Also takes in a Decompress instance. + pub fn new_with_decompress(r: R, decompress: Decompress) -> ZlibDecoder { + ZlibDecoder { + obj: r, + data: decompress, + } + } } pub fn reset_decoder_data(zlib: &mut ZlibDecoder) { diff --git a/src/zlib/read.rs b/src/zlib/read.rs index 33021304..41d5d9f8 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -3,6 +3,7 @@ use std::io::prelude::*; use super::bufread; use crate::bufreader::BufReader; +use crate::Decompress; /// A ZLIB encoder, or compressor. /// @@ -42,6 +43,14 @@ impl ZlibEncoder { inner: bufread::ZlibEncoder::new(BufReader::new(r), level), } } + + /// Same as `new` but with the ability to add a `Compress` instance rather + /// than a `Compression` instance. + pub fn new_with_compress(r: R, compress: crate::Compress) -> ZlibEncoder { + ZlibEncoder { + inner: bufread::ZlibEncoder::new_with_compress(BufReader::new(r), compress), + } + } } impl ZlibEncoder { @@ -169,6 +178,31 @@ impl ZlibDecoder { inner: bufread::ZlibDecoder::new(BufReader::with_buf(buf, r)), } } + + /// Creates a new decoder which will decompress data read from the given + /// stream. + /// + /// Also takes in a custom Decompress instance. + pub fn new_with_decompress(r: R, decompress: Decompress) -> ZlibDecoder { + ZlibDecoder::new_with_decompress_and_buf(r, vec![0; 32 * 1024], decompress) + } + + /// Same as `new_with_decompress`, but the intermediate buffer for data is specified. + /// + /// Note that the specified buffer will only be used up to its current + /// length. The buffer's capacity will also not grow over time. + pub fn new_with_decompress_and_buf( + r: R, + buf: Vec, + decompress: Decompress, + ) -> ZlibDecoder { + ZlibDecoder { + inner: bufread::ZlibDecoder::new_with_decompress( + BufReader::with_buf(buf, r), + decompress, + ), + } + } } impl ZlibDecoder { diff --git a/src/zlib/write.rs b/src/zlib/write.rs index c6718140..9cc27419 100644 --- a/src/zlib/write.rs +++ b/src/zlib/write.rs @@ -44,6 +44,14 @@ impl ZlibEncoder { } } + /// Same as `new` but with the ability to add a `Compress` instance rather + /// than a `Compression` instance. + pub fn new_with_compress(w: W, compress: crate::Compress) -> ZlibEncoder { + ZlibEncoder { + inner: zio::Writer::new(w, compress), + } + } + /// Acquires a reference to the underlying writer. pub fn get_ref(&self) -> &W { self.inner.get_ref() @@ -218,6 +226,13 @@ impl ZlibDecoder { } } + /// This is like `new` but with a supplied `Decompress` instance. + pub fn new_with_decompress(w: W, decomp: Decompress) -> ZlibDecoder { + ZlibDecoder { + inner: zio::Writer::new(w, decomp), + } + } + /// Acquires a reference to the underlying writer. pub fn get_ref(&self) -> &W { self.inner.get_ref() From 1e389c54f9ad53ac73df1fa207049d3aef23d0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pi=C3=A8rre?= <77776198+PierreV23@users.noreply.github.com> Date: Sun, 16 Jul 2023 21:23:00 +0200 Subject: [PATCH 2/4] Forgot to add grave accent's --- src/zlib/read.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zlib/read.rs b/src/zlib/read.rs index 41d5d9f8..bd6d1d2a 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -182,7 +182,7 @@ impl ZlibDecoder { /// Creates a new decoder which will decompress data read from the given /// stream. /// - /// Also takes in a custom Decompress instance. + /// Also takes in a custom `Decompress` instance. pub fn new_with_decompress(r: R, decompress: Decompress) -> ZlibDecoder { ZlibDecoder::new_with_decompress_and_buf(r, vec![0; 32 * 1024], decompress) } From acd2ab9c9000ef16fdaafbaeb338b66b8263222a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 17 Jul 2023 08:08:09 +0200 Subject: [PATCH 3/4] unify documentation style of newly added functions. It attempts to avoid referring to other functions, and instead repeats documentation from the function it is most similar to, with adjustments to show its differences. --- src/zlib/bufread.rs | 8 ++++---- src/zlib/read.rs | 27 ++++++++++++++------------- src/zlib/write.rs | 18 +++++++++++------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/zlib/bufread.rs b/src/zlib/bufread.rs index 729264ff..ff1f523d 100644 --- a/src/zlib/bufread.rs +++ b/src/zlib/bufread.rs @@ -48,12 +48,12 @@ impl ZlibEncoder { } } - /// Same as `new` but instead of passing a `Compression` instance, - /// a `Compress` instance is passed. - pub fn new_with_compress(r: R, compress: crate::Compress) -> ZlibEncoder { + /// Creates a new encoder with given `compresson` settings which will + /// read uncompressed data from the given stream `r` and emit the compressed stream. + pub fn new_with_compress(r: R, compression: crate::Compress) -> ZlibEncoder { ZlibEncoder { obj: r, - data: compress, + data: compression, } } } diff --git a/src/zlib/read.rs b/src/zlib/read.rs index bd6d1d2a..6d21fb93 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -44,11 +44,11 @@ impl ZlibEncoder { } } - /// Same as `new` but with the ability to add a `Compress` instance rather - /// than a `Compression` instance. - pub fn new_with_compress(r: R, compress: crate::Compress) -> ZlibEncoder { + /// Creates a new encoder with given `compression` settings which will + /// read uncompressed data from the given stream `r` and emit the compressed stream. + pub fn new_with_compress(r: R, compression: crate::Compress) -> ZlibEncoder { ZlibEncoder { - inner: bufread::ZlibEncoder::new_with_compress(BufReader::new(r), compress), + inner: bufread::ZlibEncoder::new_with_compress(BufReader::new(r), compression), } } } @@ -169,7 +169,8 @@ impl ZlibDecoder { ZlibDecoder::new_with_buf(r, vec![0; 32 * 1024]) } - /// Same as `new`, but the intermediate buffer for data is specified. + /// Creates a new decoder along with `buf` for intermediate data, + /// which will decompress data read from the given stream `r`. /// /// Note that the specified buffer will only be used up to its current /// length. The buffer's capacity will also not grow over time. @@ -180,26 +181,26 @@ impl ZlibDecoder { } /// Creates a new decoder which will decompress data read from the given - /// stream. - /// - /// Also takes in a custom `Decompress` instance. - pub fn new_with_decompress(r: R, decompress: Decompress) -> ZlibDecoder { - ZlibDecoder::new_with_decompress_and_buf(r, vec![0; 32 * 1024], decompress) + /// stream `r`, along with `decompression` settings + pub fn new_with_decompress(r: R, decompression: Decompress) -> ZlibDecoder { + ZlibDecoder::new_with_decompress_and_buf(r, vec![0; 32 * 1024], decompression) } - /// Same as `new_with_decompress`, but the intermediate buffer for data is specified. + /// Creates a new decoder along with `buf` for intermediate data, + /// which will decompress data read from the given stream `r`, along with + /// `decompression` settings /// /// Note that the specified buffer will only be used up to its current /// length. The buffer's capacity will also not grow over time. pub fn new_with_decompress_and_buf( r: R, buf: Vec, - decompress: Decompress, + decompression: Decompress, ) -> ZlibDecoder { ZlibDecoder { inner: bufread::ZlibDecoder::new_with_decompress( BufReader::with_buf(buf, r), - decompress, + decompression, ), } } diff --git a/src/zlib/write.rs b/src/zlib/write.rs index 9cc27419..a3f9adef 100644 --- a/src/zlib/write.rs +++ b/src/zlib/write.rs @@ -44,11 +44,11 @@ impl ZlibEncoder { } } - /// Same as `new` but with the ability to add a `Compress` instance rather - /// than a `Compression` instance. - pub fn new_with_compress(w: W, compress: crate::Compress) -> ZlibEncoder { + /// Creates a new encoder which will write compressed data to the stream + /// `w` with the given `compression` settings. + pub fn new_with_compress(w: W, compression: crate::Compress) -> ZlibEncoder { ZlibEncoder { - inner: zio::Writer::new(w, compress), + inner: zio::Writer::new(w, compression), } } @@ -226,10 +226,14 @@ impl ZlibDecoder { } } - /// This is like `new` but with a supplied `Decompress` instance. - pub fn new_with_decompress(w: W, decomp: Decompress) -> ZlibDecoder { + /// Creates a new decoder which will write uncompressed data to the stream `w` + /// using the given `decompression` settings. + /// + /// When this decoder is dropped or unwrapped the final pieces of data will + /// be flushed. + pub fn new_with_decompress(w: W, decompression: Decompress) -> ZlibDecoder { ZlibDecoder { - inner: zio::Writer::new(w, decomp), + inner: zio::Writer::new(w, decompression), } } From c9fe661d150b0750385c77796b351bd62760bcde Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 25 Jul 2023 13:03:04 +0200 Subject: [PATCH 4/4] further unify documentation, make sure sentences end with a period. --- src/zlib/bufread.rs | 12 +++++------- src/zlib/read.rs | 14 +++++++------- src/zlib/write.rs | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/zlib/bufread.rs b/src/zlib/bufread.rs index ff1f523d..aa8af64f 100644 --- a/src/zlib/bufread.rs +++ b/src/zlib/bufread.rs @@ -48,9 +48,9 @@ impl ZlibEncoder { } } - /// Creates a new encoder with given `compresson` settings which will + /// Creates a new encoder with the given `compression` settings which will /// read uncompressed data from the given stream `r` and emit the compressed stream. - pub fn new_with_compress(r: R, compression: crate::Compress) -> ZlibEncoder { + pub fn new_with_compress(r: R, compression: Compress) -> ZlibEncoder { ZlibEncoder { obj: r, data: compression, @@ -176,13 +176,11 @@ impl ZlibDecoder { } /// Creates a new decoder which will decompress data read from the given - /// stream. - /// - /// Also takes in a Decompress instance. - pub fn new_with_decompress(r: R, decompress: Decompress) -> ZlibDecoder { + /// stream, using the given `decompression` settings. + pub fn new_with_decompress(r: R, decompression: Decompress) -> ZlibDecoder { ZlibDecoder { obj: r, - data: decompress, + data: decompression, } } } diff --git a/src/zlib/read.rs b/src/zlib/read.rs index 6d21fb93..b65418be 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -44,7 +44,7 @@ impl ZlibEncoder { } } - /// Creates a new encoder with given `compression` settings which will + /// Creates a new encoder with the given `compression` settings which will /// read uncompressed data from the given stream `r` and emit the compressed stream. pub fn new_with_compress(r: R, compression: crate::Compress) -> ZlibEncoder { ZlibEncoder { @@ -169,8 +169,8 @@ impl ZlibDecoder { ZlibDecoder::new_with_buf(r, vec![0; 32 * 1024]) } - /// Creates a new decoder along with `buf` for intermediate data, - /// which will decompress data read from the given stream `r`. + /// Creates a new decoder which will decompress data read from the given + /// stream `r`, using `buf` as backing to speed up reading. /// /// Note that the specified buffer will only be used up to its current /// length. The buffer's capacity will also not grow over time. @@ -181,14 +181,14 @@ impl ZlibDecoder { } /// Creates a new decoder which will decompress data read from the given - /// stream `r`, along with `decompression` settings + /// stream `r`, along with `decompression` settings. pub fn new_with_decompress(r: R, decompression: Decompress) -> ZlibDecoder { ZlibDecoder::new_with_decompress_and_buf(r, vec![0; 32 * 1024], decompression) } - /// Creates a new decoder along with `buf` for intermediate data, - /// which will decompress data read from the given stream `r`, along with - /// `decompression` settings + /// Creates a new decoder which will decompress data read from the given + /// stream `r`, using `buf` as backing to speed up reading, + /// along with `decompression` settings to configure decoder. /// /// Note that the specified buffer will only be used up to its current /// length. The buffer's capacity will also not grow over time. diff --git a/src/zlib/write.rs b/src/zlib/write.rs index a3f9adef..d8ad2f26 100644 --- a/src/zlib/write.rs +++ b/src/zlib/write.rs @@ -46,7 +46,7 @@ impl ZlibEncoder { /// Creates a new encoder which will write compressed data to the stream /// `w` with the given `compression` settings. - pub fn new_with_compress(w: W, compression: crate::Compress) -> ZlibEncoder { + pub fn new_with_compress(w: W, compression: Compress) -> ZlibEncoder { ZlibEncoder { inner: zio::Writer::new(w, compression), }