compression: deflate: move encoder into a mod

This allows to add a decompression mod inside the deflate mod. This does
not touch the public API.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
Tested-by: Max Carrara <m.carrara@proxmox.com>
This commit is contained in:
Maximiliano Sandoval 2024-07-05 15:04:28 +02:00 committed by Wolfgang Bumiller
parent 7ae351854e
commit 70a71e0c8e
4 changed files with 10 additions and 7 deletions

View File

@ -12,8 +12,6 @@ use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use proxmox_io::ByteBuffer;
use proxmox_lang::io_format_err;
const BUFFER_SIZE: usize = 8192;
pub enum Level {
Fastest,
Best,
@ -53,7 +51,7 @@ impl<T> DeflateEncoder<T> {
Self {
inner,
compressor: Compress::new(level, false),
buffer: ByteBuffer::with_capacity(BUFFER_SIZE),
buffer: ByteBuffer::with_capacity(super::BUFFER_SIZE),
input_buffer: Bytes::new(),
state: EncoderState::Reading,
}
@ -109,7 +107,7 @@ impl<T: AsyncWrite + Unpin> DeflateEncoder<T> {
where
R: AsyncRead + Unpin,
{
let mut buffer = ByteBuffer::with_capacity(BUFFER_SIZE);
let mut buffer = ByteBuffer::with_capacity(super::BUFFER_SIZE);
let mut eof = false;
loop {
if !eof && !buffer.is_full() {

View File

@ -0,0 +1,5 @@
mod compression;
pub use compression::{DeflateEncoder, Level};
const BUFFER_SIZE: usize = 8192;

View File

@ -1,8 +1,8 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
mod compression;
pub use compression::*;
pub use deflate::{DeflateEncoder, Level};
mod deflate;
pub mod tar;
pub mod zip;
pub mod zstd;

View File

@ -22,7 +22,7 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
use crc32fast::Hasher;
use proxmox_time::gmtime;
use crate::compression::{DeflateEncoder, Level};
use crate::deflate::{DeflateEncoder, Level};
const LOCAL_FH_SIG: u32 = 0x04034B50;
const LOCAL_FF_SIG: u32 = 0x08074B50;