mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-22 20:36:38 +00:00
build(deps): bump the dependencies group with 19 updates (#1745)
This commit is contained in:
+20
-42
@@ -12,9 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// use async_zip::tokio::read::seek::ZipFileReader;
|
||||
// use async_zip::tokio::write::ZipFileWriter;
|
||||
// use async_zip::{Compression, ZipEntryBuilder};
|
||||
use async_compression::tokio::bufread::{BzDecoder, GzipDecoder, XzDecoder, ZlibDecoder, ZstdDecoder};
|
||||
use async_compression::tokio::write::{BzEncoder, GzipEncoder, XzEncoder, ZlibEncoder, ZstdEncoder};
|
||||
use std::path::Path;
|
||||
@@ -115,6 +112,15 @@ impl CompressionFormat {
|
||||
|
||||
Ok(decoder)
|
||||
}
|
||||
/// Convert CompressionLevel to async_compression::Level
|
||||
fn convert_level(level: CompressionLevel) -> async_compression::Level {
|
||||
match level {
|
||||
CompressionLevel::Fastest => async_compression::Level::Fastest,
|
||||
CompressionLevel::Best => async_compression::Level::Best,
|
||||
CompressionLevel::Default => async_compression::Level::Default,
|
||||
CompressionLevel::Level(n) => async_compression::Level::Precise(n as i32),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create compressor
|
||||
pub fn get_encoder<W>(&self, output: W, level: CompressionLevel) -> io::Result<Box<dyn AsyncWrite + Send + Unpin>>
|
||||
@@ -125,48 +131,23 @@ impl CompressionFormat {
|
||||
|
||||
let encoder: Box<dyn AsyncWrite + Send + Unpin + 'static> = match self {
|
||||
CompressionFormat::Gzip => {
|
||||
let level = match level {
|
||||
CompressionLevel::Fastest => async_compression::Level::Fastest,
|
||||
CompressionLevel::Best => async_compression::Level::Best,
|
||||
CompressionLevel::Default => async_compression::Level::Default,
|
||||
CompressionLevel::Level(n) => async_compression::Level::Precise(n as i32),
|
||||
};
|
||||
let level = Self::convert_level(level);
|
||||
Box::new(GzipEncoder::with_quality(writer, level))
|
||||
}
|
||||
CompressionFormat::Bzip2 => {
|
||||
let level = match level {
|
||||
CompressionLevel::Fastest => async_compression::Level::Fastest,
|
||||
CompressionLevel::Best => async_compression::Level::Best,
|
||||
CompressionLevel::Default => async_compression::Level::Default,
|
||||
CompressionLevel::Level(n) => async_compression::Level::Precise(n as i32),
|
||||
};
|
||||
let level = Self::convert_level(level);
|
||||
Box::new(BzEncoder::with_quality(writer, level))
|
||||
}
|
||||
CompressionFormat::Zlib => {
|
||||
let level = match level {
|
||||
CompressionLevel::Fastest => async_compression::Level::Fastest,
|
||||
CompressionLevel::Best => async_compression::Level::Best,
|
||||
CompressionLevel::Default => async_compression::Level::Default,
|
||||
CompressionLevel::Level(n) => async_compression::Level::Precise(n as i32),
|
||||
};
|
||||
let level = Self::convert_level(level);
|
||||
Box::new(ZlibEncoder::with_quality(writer, level))
|
||||
}
|
||||
CompressionFormat::Xz => {
|
||||
let level = match level {
|
||||
CompressionLevel::Fastest => async_compression::Level::Fastest,
|
||||
CompressionLevel::Best => async_compression::Level::Best,
|
||||
CompressionLevel::Default => async_compression::Level::Default,
|
||||
CompressionLevel::Level(n) => async_compression::Level::Precise(n as i32),
|
||||
};
|
||||
let level = Self::convert_level(level);
|
||||
Box::new(XzEncoder::with_quality(writer, level))
|
||||
}
|
||||
CompressionFormat::Zstd => {
|
||||
let level = match level {
|
||||
CompressionLevel::Fastest => async_compression::Level::Fastest,
|
||||
CompressionLevel::Best => async_compression::Level::Best,
|
||||
CompressionLevel::Default => async_compression::Level::Default,
|
||||
CompressionLevel::Level(n) => async_compression::Level::Precise(n as i32),
|
||||
};
|
||||
let level = Self::convert_level(level);
|
||||
Box::new(ZstdEncoder::with_quality(writer, level))
|
||||
}
|
||||
CompressionFormat::Tar => Box::new(writer),
|
||||
@@ -189,7 +170,7 @@ impl CompressionFormat {
|
||||
pub async fn decompress<R, F>(input: R, format: CompressionFormat, mut callback: F) -> io::Result<()>
|
||||
where
|
||||
R: AsyncRead + Send + Unpin + 'static,
|
||||
F: AsyncFnMut(tokio_tar::Entry<Archive<Box<dyn AsyncRead + Send + Unpin + 'static>>>) -> std::io::Result<()> + Send + 'static,
|
||||
F: AsyncFnMut(tokio_tar::Entry<Archive<Box<dyn AsyncRead + Send + Unpin + 'static>>>) -> io::Result<()> + Send + 'static,
|
||||
{
|
||||
let decoder = format.get_decoder(input)?;
|
||||
let mut ar = Archive::new(decoder);
|
||||
@@ -258,7 +239,7 @@ impl Compressor {
|
||||
let cursor = std::io::Cursor::new(output);
|
||||
let mut encoder = self.format.get_encoder(cursor, self.level)?;
|
||||
|
||||
tokio::io::copy(&mut std::io::Cursor::new(input), &mut encoder).await?;
|
||||
io::copy(&mut std::io::Cursor::new(input), &mut encoder).await?;
|
||||
encoder.shutdown().await?;
|
||||
|
||||
// Get compressed data
|
||||
@@ -273,7 +254,7 @@ impl Compressor {
|
||||
let cursor = std::io::Cursor::new(input);
|
||||
let mut decoder = self.format.get_decoder(cursor)?;
|
||||
|
||||
tokio::io::copy(&mut decoder, &mut output).await?;
|
||||
io::copy(&mut decoder, &mut output).await?;
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
@@ -302,7 +283,7 @@ impl Decompressor {
|
||||
let mut decoder = self.format.get_decoder(input_file)?;
|
||||
let mut writer = BufWriter::new(output_file);
|
||||
|
||||
tokio::io::copy(&mut decoder, &mut writer).await?;
|
||||
io::copy(&mut decoder, &mut writer).await?;
|
||||
writer.shutdown().await?;
|
||||
|
||||
Ok(())
|
||||
@@ -538,15 +519,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_compression_format_memory_efficiency() {
|
||||
// Test memory efficiency of enum
|
||||
use std::mem;
|
||||
|
||||
// Verify enum size is reasonable
|
||||
let size = mem::size_of::<CompressionFormat>();
|
||||
let size = size_of::<CompressionFormat>();
|
||||
assert!(size <= 8, "CompressionFormat should be memory efficient, got {size} bytes");
|
||||
|
||||
// Verify Option<CompressionFormat> size
|
||||
let option_size = mem::size_of::<Option<CompressionFormat>>();
|
||||
let option_size = size_of::<Option<CompressionFormat>>();
|
||||
assert!(
|
||||
option_size <= 16,
|
||||
"Option<CompressionFormat> should be efficient, got {option_size} bytes"
|
||||
|
||||
Reference in New Issue
Block a user