Skip to content

Commit 91751a3

Browse files
authored
Merge pull request #268 from nyurik/brotli-upgrade
Upgrade to Brotli v5
2 parents 85d45d9 + f4024f2 commit 91751a3

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ zstdmt = ["zstd", "zstd-safe/zstdmt"]
3232
deflate64 = ["dep:deflate64"]
3333

3434
[dependencies]
35-
brotli = { version = "4.0", optional = true, default-features = false, features = ["std"] }
35+
brotli = { version = "5.0", optional = true }
3636
bzip2 = { version = "0.4.4", optional = true }
3737
flate2 = { version = "1.0.13", optional = true }
3838
futures-core = { version = "0.3", default-features = false }

src/codec/brotli/encoder.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use std::{fmt, io};
33

44
use brotli::enc::{
55
backward_references::BrotliEncoderParams,
6-
encode::{
7-
BrotliEncoderCompressStream, BrotliEncoderCreateInstance, BrotliEncoderHasMoreOutput,
8-
BrotliEncoderIsFinished, BrotliEncoderOperation, BrotliEncoderStateStruct,
9-
},
6+
encode::{BrotliEncoderOperation, BrotliEncoderStateStruct},
107
StandardAlloc,
118
};
129

@@ -16,7 +13,7 @@ pub struct BrotliEncoder {
1613

1714
impl BrotliEncoder {
1815
pub(crate) fn new(params: BrotliEncoderParams) -> Self {
19-
let mut state = BrotliEncoderCreateInstance(StandardAlloc::default());
16+
let mut state = BrotliEncoderStateStruct::new(StandardAlloc::default());
2017
state.params = params;
2118
Self { state }
2219
}
@@ -33,8 +30,7 @@ impl BrotliEncoder {
3330
let mut input_len = 0;
3431
let mut output_len = 0;
3532

36-
if BrotliEncoderCompressStream(
37-
&mut self.state,
33+
if !self.state.compress_stream(
3834
op,
3935
&mut in_buf.len(),
4036
in_buf,
@@ -44,8 +40,7 @@ impl BrotliEncoder {
4440
&mut output_len,
4541
&mut None,
4642
&mut |_, _, _, _| (),
47-
) <= 0
48-
{
43+
) {
4944
return Err(io::Error::new(io::ErrorKind::Other, "brotli error"));
5045
}
5146

@@ -79,7 +74,7 @@ impl Encode for BrotliEncoder {
7974
BrotliEncoderOperation::BROTLI_OPERATION_FLUSH,
8075
)?;
8176

82-
Ok(BrotliEncoderHasMoreOutput(&self.state) == 0)
77+
Ok(!self.state.has_more_output())
8378
}
8479

8580
fn finish(
@@ -92,7 +87,7 @@ impl Encode for BrotliEncoder {
9287
BrotliEncoderOperation::BROTLI_OPERATION_FINISH,
9388
)?;
9489

95-
Ok(BrotliEncoderIsFinished(&self.state) == 1)
90+
Ok(self.state.is_finished())
9691
}
9792
}
9893

0 commit comments

Comments
 (0)