use std::io;
use async_compression::{Level, tokio::bufread::GzipEncoder};
use futures::TryStreamExt;
use tokio::io::BufReader;
use tokio_util::io::{ReaderStream, StreamReader};
use crate::MiasmaStream;
const COMPRESS_BUFFER_SIZE: usize = 1024 * 4;
pub fn gzip_stream<E>(stream: impl MiasmaStream<E>) -> impl MiasmaStream<io::Error>
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
let stream = stream.map_err(io::Error::other);
let reader = StreamReader::new(stream);
let buf = BufReader::with_capacity(COMPRESS_BUFFER_SIZE, reader);
let encoder = GzipEncoder::with_quality(
buf,
Level::Precise(i32::MAX),
);
ReaderStream::new(encoder)
}