Skip to content

Commit

Permalink
try brotli
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 19, 2023
1 parent 036c841 commit d826dda
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 61 deletions.
87 changes: 37 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rust-version = "1.63"
[dependencies]
abao = { version = "0.2.0", features = ["group_size_16k", "tokio_io"], default-features = false }
anyhow = { version = "1", features = ["backtrace"] }
async-compression = { version = "0.3.15", features = ["tokio", "zstd"] }
async-compression = { version = "0.3.15", features = ["tokio", "brotli"] }
base64 = "0.21.0"
blake3 = "1.3.3"
bytes = "1"
Expand Down
4 changes: 2 additions & 2 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Stats {
pub struct DataStream(AsyncSliceDecoder<RecvStream>);

type RecvStream =
async_compression::tokio::bufread::ZstdDecoder<tokio::io::BufReader<quinn::RecvStream>>;
async_compression::tokio::bufread::BrotliDecoder<tokio::io::BufReader<quinn::RecvStream>>;

impl DataStream {
fn new(inner: RecvStream, hash: Hash) -> Self {
Expand Down Expand Up @@ -284,7 +284,7 @@ async fn handle_blob_response(
assert!(buffer.is_empty());
// Decompress data
let decompress_reader =
async_compression::tokio::bufread::ZstdDecoder::new(reader);
async_compression::tokio::bufread::BrotliDecoder::new(reader);
let decoder = DataStream::new(decompress_reader, hash);
Ok(decoder)
}
Expand Down
15 changes: 7 additions & 8 deletions src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,14 +838,10 @@ async fn send_blob<W: AsyncWrite + Unpin + Send + 'static>(
// taking a reference does not work. spawn_blocking requires
// 'static lifetime.

writer = tokio::task::spawn_blocking(move || {
// Compress data
let mut compressed_writer =
async_compression::tokio::write::ZstdEncoder::with_quality(
writer,
async_compression::Level::Fastest,
);
// Compress data
let mut compressed_writer = async_compression::tokio::write::BrotliEncoder::new(writer);

compressed_writer = tokio::task::spawn_blocking(move || {
let file_reader = std::fs::File::open(&path)?;
let outboard_reader = std::io::Cursor::new(outboard);
let mut wrapper = SyncIoBridge::new(&mut compressed_writer);
Expand All @@ -856,10 +852,13 @@ async fn send_blob<W: AsyncWrite + Unpin + Send + 'static>(
size,
);
let _copied = std::io::copy(&mut slice_extractor, &mut wrapper)?;
std::io::Result::Ok(compressed_writer.into_inner())
std::io::Result::Ok(compressed_writer)
})
.await??;

compressed_writer.flush().await?;
let writer = compressed_writer.into_inner();

Ok((SentStatus::Sent, writer, size))
}
_ => {
Expand Down

0 comments on commit d826dda

Please sign in to comment.