mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
optimize:replace size magic number -1 with SIZE_TRANSFORMED constant (#1542)
This commit is contained in:
@@ -161,6 +161,8 @@ pin_project! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HashReader {
|
impl HashReader {
|
||||||
|
/// Used for transformation layers (compression/encryption)
|
||||||
|
pub const SIZE_PRESERVE_LAYER: i64 = -1;
|
||||||
pub fn new(
|
pub fn new(
|
||||||
mut inner: Box<dyn Reader>,
|
mut inner: Box<dyn Reader>,
|
||||||
size: i64,
|
size: i64,
|
||||||
@@ -169,7 +171,8 @@ impl HashReader {
|
|||||||
sha256hex: Option<String>,
|
sha256hex: Option<String>,
|
||||||
diskable_md5: bool,
|
diskable_md5: bool,
|
||||||
) -> std::io::Result<Self> {
|
) -> std::io::Result<Self> {
|
||||||
if size >= 0
|
// Get the innermost HashReader
|
||||||
|
if size != Self::SIZE_PRESERVE_LAYER
|
||||||
&& let Some(existing_hash_reader) = inner.as_hash_reader_mut()
|
&& let Some(existing_hash_reader) = inner.as_hash_reader_mut()
|
||||||
{
|
{
|
||||||
if existing_hash_reader.bytes_read() > 0 {
|
if existing_hash_reader.bytes_read() > 0 {
|
||||||
|
|||||||
@@ -670,7 +670,7 @@ impl FS {
|
|||||||
let hrd = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
let hrd = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
||||||
|
|
||||||
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
||||||
size = -1;
|
size = HashReader::SIZE_PRESERVE_LAYER;
|
||||||
}
|
}
|
||||||
|
|
||||||
let hrd = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
let hrd = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
||||||
@@ -1222,7 +1222,7 @@ impl S3 for FS {
|
|||||||
// let hrd = HashReader::new(reader, length, actual_size, None, false).map_err(ApiError::from)?;
|
// let hrd = HashReader::new(reader, length, actual_size, None, false).map_err(ApiError::from)?;
|
||||||
|
|
||||||
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
||||||
length = -1;
|
length = HashReader::SIZE_PRESERVE_LAYER;
|
||||||
} else {
|
} else {
|
||||||
src_info
|
src_info
|
||||||
.user_defined
|
.user_defined
|
||||||
@@ -3699,7 +3699,7 @@ impl S3 for FS {
|
|||||||
opts.want_checksum = hrd.checksum();
|
opts.want_checksum = hrd.checksum();
|
||||||
|
|
||||||
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
||||||
size = -1;
|
size = HashReader::SIZE_PRESERVE_LAYER;
|
||||||
md5hex = None;
|
md5hex = None;
|
||||||
sha256hex = None;
|
sha256hex = None;
|
||||||
}
|
}
|
||||||
@@ -4211,7 +4211,7 @@ impl S3 for FS {
|
|||||||
|
|
||||||
let compress_reader = CompressReader::new(hrd, CompressionAlgorithm::default());
|
let compress_reader = CompressReader::new(hrd, CompressionAlgorithm::default());
|
||||||
reader = Box::new(compress_reader);
|
reader = Box::new(compress_reader);
|
||||||
size = -1;
|
size = HashReader::SIZE_PRESERVE_LAYER;
|
||||||
md5hex = None;
|
md5hex = None;
|
||||||
sha256hex = None;
|
sha256hex = None;
|
||||||
}
|
}
|
||||||
@@ -4439,7 +4439,7 @@ impl S3 for FS {
|
|||||||
if is_compressible {
|
if is_compressible {
|
||||||
let hrd = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
let hrd = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
||||||
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
reader = Box::new(CompressReader::new(hrd, CompressionAlgorithm::default()));
|
||||||
size = -1;
|
size = HashReader::SIZE_PRESERVE_LAYER;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut reader = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
let mut reader = HashReader::new(reader, size, actual_size, None, None, false).map_err(ApiError::from)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user