Skip to content

Commit

Permalink
Merge pull request #268 from nyurik/brotli-upgrade
Browse files Browse the repository at this point in the history
Upgrade to Brotli v5
  • Loading branch information
NobodyXu authored Apr 25, 2024
2 parents 85d45d9 + f4024f2 commit 91751a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ zstdmt = ["zstd", "zstd-safe/zstdmt"]
deflate64 = ["dep:deflate64"]

[dependencies]
brotli = { version = "4.0", optional = true, default-features = false, features = ["std"] }
brotli = { version = "5.0", optional = true }
bzip2 = { version = "0.4.4", optional = true }
flate2 = { version = "1.0.13", optional = true }
futures-core = { version = "0.3", default-features = false }
Expand Down
17 changes: 6 additions & 11 deletions src/codec/brotli/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::{fmt, io};

use brotli::enc::{
backward_references::BrotliEncoderParams,
encode::{
BrotliEncoderCompressStream, BrotliEncoderCreateInstance, BrotliEncoderHasMoreOutput,
BrotliEncoderIsFinished, BrotliEncoderOperation, BrotliEncoderStateStruct,
},
encode::{BrotliEncoderOperation, BrotliEncoderStateStruct},
StandardAlloc,
};

Expand All @@ -16,7 +13,7 @@ pub struct BrotliEncoder {

impl BrotliEncoder {
pub(crate) fn new(params: BrotliEncoderParams) -> Self {
let mut state = BrotliEncoderCreateInstance(StandardAlloc::default());
let mut state = BrotliEncoderStateStruct::new(StandardAlloc::default());
state.params = params;
Self { state }
}
Expand All @@ -33,8 +30,7 @@ impl BrotliEncoder {
let mut input_len = 0;
let mut output_len = 0;

if BrotliEncoderCompressStream(
&mut self.state,
if !self.state.compress_stream(
op,
&mut in_buf.len(),
in_buf,
Expand All @@ -44,8 +40,7 @@ impl BrotliEncoder {
&mut output_len,
&mut None,
&mut |_, _, _, _| (),
) <= 0
{
) {
return Err(io::Error::new(io::ErrorKind::Other, "brotli error"));
}

Expand Down Expand Up @@ -79,7 +74,7 @@ impl Encode for BrotliEncoder {
BrotliEncoderOperation::BROTLI_OPERATION_FLUSH,
)?;

Ok(BrotliEncoderHasMoreOutput(&self.state) == 0)
Ok(!self.state.has_more_output())
}

fn finish(
Expand All @@ -92,7 +87,7 @@ impl Encode for BrotliEncoder {
BrotliEncoderOperation::BROTLI_OPERATION_FINISH,
)?;

Ok(BrotliEncoderIsFinished(&self.state) == 1)
Ok(self.state.is_finished())
}
}

Expand Down

0 comments on commit 91751a3

Please sign in to comment.