Skip to content

Commit f6886ff

Browse files
committed
Separate codecs as a separate crate, allow direct configuration
* git mv all codecs into a new `compression-codecs` crate to retain git history * Add missing constructors to all codecs to allow custom configuration * Exposes custom codec constructions with `with_codec` as an alternative * Updated `README.md` to include PR checks Fixes #324, #359
1 parent ebae65f commit f6886ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1463
-599
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/target
22
**/*.rs.bk
33

4+
wasi-sysroot*.tar.gz
5+
wasi-sysroot/
6+
47
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
58
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
69
Cargo.lock

Cargo.toml

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
[package]
2-
name = "async-compression"
3-
version = "0.4.27"
4-
authors = ["Wim Looman <[email protected]>", "Allen Bui <[email protected]>"]
5-
edition = "2018"
1+
[workspace]
2+
members = ["crates/*"]
63
resolver = "2"
4+
5+
[workspace.package]
6+
authors = ["Wim Looman <[email protected]>", "Allen Bui <[email protected]>"]
77
license = "MIT OR Apache-2.0"
8-
keywords = ["compression", "gzip", "zstd", "brotli", "async"]
9-
categories = ["compression", "asynchronous"]
108
repository = "https://github.com/Nullus157/async-compression"
9+
categories = ["compression", "asynchronous"]
10+
version = "0.4.27"
11+
edition = "2018"
12+
13+
[workspace.dependencies]
14+
compression-codecs = { path = "crates/compression-codecs" }
15+
compression-core = { path = "crates/compression-core" }
16+
futures-core = { version = "0.3", default-features = false }
17+
memchr = "2"
18+
pin-project-lite = "0.2"
19+
20+
[package]
21+
name = "async-compression"
1122
description = """
1223
Adaptors between compression crates and Rust's modern asynchronous IO types.
1324
"""
25+
version.workspace = true
26+
authors.workspace = true
27+
license.workspace = true
28+
categories.workspace = true
29+
edition.workspace = true
1430

1531
[package.metadata.docs.rs]
1632
all-features = true
@@ -20,31 +36,52 @@ rustdoc-args = ["--cfg", "docsrs"]
2036
# groups
2137
all = ["all-implementations", "all-algorithms"]
2238
all-implementations = ["futures-io", "tokio"]
23-
all-algorithms = ["brotli", "bzip2", "deflate", "gzip", "lz4", "lzma", "xz-parallel", "xz", "zlib", "zstd", "deflate64"]
39+
all-algorithms = [
40+
"brotli",
41+
"bzip2",
42+
"deflate",
43+
"deflate64",
44+
"gzip",
45+
"lz4",
46+
"lzma",
47+
"xz",
48+
"xz-parallel",
49+
"zlib",
50+
"zstd",
51+
]
2452

2553
# algorithms
26-
deflate = ["flate2"]
27-
gzip = ["flate2"]
28-
lz4 = ["dep:lz4"]
29-
lzma = ["dep:liblzma"]
30-
xz = ["lzma"]
31-
xz-parallel = ["xz", "liblzma/parallel"]
32-
xz2 = ["xz"]
33-
zlib = ["flate2"]
34-
zstd = ["libzstd", "zstd-safe"]
35-
zstdmt = ["zstd", "zstd-safe/zstdmt"]
36-
deflate64 = ["dep:deflate64"]
54+
brotli = ["compression-codecs/brotli", "dep:brotli"]
55+
bzip2 = ["compression-codecs/bzip2", "dep:bzip2"]
56+
deflate = ["compression-codecs/deflate", "flate2"]
57+
deflate64 = ["compression-codecs/deflate64", "dep:deflate64"]
58+
gzip = ["compression-codecs/gzip", "flate2"]
59+
lz4 = ["compression-codecs/lz4", "dep:lz4"]
60+
lzma = ["compression-codecs/lzma", "liblzma"]
61+
xz = ["compression-codecs/xz", "lzma"]
62+
xz-parallel = ["compression-codecs/xz-parallel", "xz", "liblzma/parallel"]
63+
xz2 = ["compression-codecs/xz2", "xz"]
64+
zlib = ["compression-codecs/zlib", "flate2"]
65+
zstd = ["compression-codecs/zstd", "libzstd", "zstd-safe"]
66+
zstdmt = ["compression-codecs/zstdmt", "zstd", "zstd-safe/zstdmt"]
67+
3768

3869
[dependencies]
70+
# core dependencies
71+
futures-core.workspace = true
72+
memchr.workspace = true
73+
pin-project-lite.workspace = true
74+
compression-codecs.workspace = true
75+
compression-core.workspace = true
76+
# optionals deps
3977
brotli = { version = "8", optional = true }
4078
bzip2 = { version = "0.6", optional = true }
4179
flate2 = { version = "1.0.13", optional = true }
42-
futures-core = { version = "0.3", default-features = false }
43-
futures-io = { version = "0.3", default-features = false, features = ["std"], optional = true }
80+
futures-io = { version = "0.3", default-features = false, features = [
81+
"std",
82+
], optional = true }
4483
libzstd = { package = "zstd", version = "0.13.1", optional = true, default-features = false }
4584
lz4 = { version = "1.28.1", optional = true }
46-
memchr = "2"
47-
pin-project-lite = "0.2"
4885
tokio = { version = "1.24.2", optional = true, default-features = false }
4986
liblzma = { version = "0.4.2", optional = true }
5087
zstd-safe = { version = "7", optional = true, default-features = false }
@@ -58,7 +95,12 @@ ntest = "0.9"
5895
proptest = "1"
5996
proptest-derive = "0.6"
6097
rand = "0.9"
61-
tokio = { version = "1.38.2", default-features = false, features = ["io-util", "macros", "rt-multi-thread", "io-std"] }
98+
tokio = { version = "1.38.2", default-features = false, features = [
99+
"io-util",
100+
"macros",
101+
"rt-multi-thread",
102+
"io-std",
103+
] }
62104
tokio-util = { version = "0.7", default-features = false, features = ["io"] }
63105

64106
[[test]]
@@ -112,3 +154,8 @@ required-features = ["zlib", "tokio"]
112154
[[example]]
113155
name = "zstd_gzip"
114156
required-features = ["zstd", "gzip", "tokio"]
157+
158+
159+
[[example]]
160+
name = "lzma_filters"
161+
required-features = ["xz", "tokio"]

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,43 @@ enable different subsets of features as appropriate for the code you are
2020
testing to avoid compiling all dependencies, e.g. `cargo test --features
2121
tokio,gzip`.
2222

23+
To prepare for a pull request, you can run several other checks:
24+
25+
1. `fmt`
26+
27+
```bash
28+
cargo fmt --all
29+
cargo clippy --no-deps
30+
```
31+
32+
2. `build`
33+
34+
```bash
35+
cargo build --lib --all-features
36+
```
37+
38+
3. `nextest`
39+
40+
```bash
41+
cargo --locked nextest run --workspace --all-features
42+
```
43+
44+
4. `hack check`
45+
46+
```bash
47+
cargo hack check --workspace --feature-powerset --all-targets --skip 'all,all-algorithms,all-implementations'
48+
```
49+
50+
5. `wasm32` - Linux only
51+
52+
```bash
53+
gh release download --repo WebAssembly/wasi-sdk --pattern 'wasi-sysroot-*.tar.gz'
54+
rustup target add wasm32-wasip1-threads
55+
56+
export "CFLAGS_wasm32_wasip1_threads=--sysroot=\"${PWD}/wasi-sysroot\" -I\"${PWD}/wasi-sysroot/include/wasm32-wasip1-threads\" -L-I\"${PWD}/wasi-sysroot/lib/wasm32-wasip1-threads\""
57+
cargo build --lib --features all-implementations,brotli,bzip2,deflate,gzip,lz4,lzma,xz,zlib,zstd,deflate64 --target wasm32-wasip1-threads
58+
```
59+
2360
## License
2461

2562
Licensed under either of
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[package]
2+
name = "compression-codecs"
3+
description = """
4+
Adaptors for various compression algorithms.
5+
"""
6+
version.workspace = true
7+
authors.workspace = true
8+
license.workspace = true
9+
categories.workspace = true
10+
edition.workspace = true
11+
12+
[features]
13+
all-algorithms = [
14+
"brotli",
15+
"bzip2",
16+
"deflate",
17+
"gzip",
18+
"lz4",
19+
"lzma",
20+
"xz-parallel",
21+
"xz",
22+
"zlib",
23+
"zstd",
24+
"deflate64",
25+
]
26+
27+
# algorithms
28+
deflate = ["flate2"]
29+
gzip = ["flate2"]
30+
lz4 = ["dep:lz4"]
31+
lzma = ["dep:liblzma"]
32+
xz = ["lzma"]
33+
xz-parallel = ["xz", "liblzma/parallel"]
34+
xz2 = ["xz"]
35+
zlib = ["flate2"]
36+
zstd = ["libzstd", "zstd-safe"]
37+
zstdmt = ["zstd", "zstd-safe/zstdmt"]
38+
deflate64 = ["dep:deflate64"]
39+
40+
41+
[dependencies]
42+
# Workspace dependencies.
43+
compression-core.workspace = true
44+
futures-core.workspace = true
45+
memchr.workspace = true
46+
pin-project-lite.workspace = true
47+
# features
48+
brotli = { version = "8", optional = true }
49+
bzip2 = { version = "0.6", optional = true }
50+
flate2 = { version = "1.0.13", optional = true }
51+
libzstd = { package = "zstd", version = "0.13.1", optional = true, default-features = false }
52+
lz4 = { version = "1.28.1", optional = true }
53+
liblzma = { version = "0.4.2", optional = true }
54+
zstd-safe = { version = "7", optional = true, default-features = false }
55+
deflate64 = { version = "0.1.5", optional = true }

src/codec/brotli/decoder.rs renamed to crates/compression-codecs/src/brotli/decoder.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use crate::{codec::Decode, util::PartialBuffer};
2-
use std::{fmt, io};
3-
1+
use crate::Decode;
42
use brotli::{enc::StandardAlloc, BrotliDecompressStream, BrotliResult, BrotliState};
3+
use compression_core::util::PartialBuffer;
4+
use std::{fmt, io};
55

66
pub struct BrotliDecoder {
77
// `BrotliState` is very large (over 2kb) which is why we're boxing it.
88
state: Box<BrotliState<StandardAlloc, StandardAlloc, StandardAlloc>>,
99
}
1010

11-
impl BrotliDecoder {
12-
pub(crate) fn new() -> Self {
11+
impl Default for BrotliDecoder {
12+
fn default() -> Self {
1313
Self {
1414
state: Box::new(BrotliState::new(
1515
StandardAlloc::default(),
@@ -18,14 +18,20 @@ impl BrotliDecoder {
1818
)),
1919
}
2020
}
21+
}
22+
23+
impl BrotliDecoder {
24+
pub fn new() -> Self {
25+
Self::default()
26+
}
2127

2228
fn decode(
2329
&mut self,
2430
input: &mut PartialBuffer<impl AsRef<[u8]>>,
2531
output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,
2632
) -> io::Result<BrotliResult> {
2733
let in_buf = input.unwritten();
28-
let mut out_buf = output.unwritten_mut();
34+
let out_buf = output.unwritten_mut();
2935

3036
let mut input_len = 0;
3137
let mut output_len = 0;

src/codec/brotli/encoder.rs renamed to crates/compression-codecs/src/brotli/encoder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
use crate::{codec::Encode, util::PartialBuffer};
2-
use std::{fmt, io};
3-
1+
use crate::{brotli::params::EncoderParams, Encode};
42
use brotli::enc::{
53
backward_references::BrotliEncoderParams,
64
encode::{BrotliEncoderOperation, BrotliEncoderStateStruct},
75
StandardAlloc,
86
};
7+
use compression_core::util::PartialBuffer;
8+
use std::{fmt, io};
99

1010
pub struct BrotliEncoder {
1111
state: BrotliEncoderStateStruct<StandardAlloc>,
1212
}
1313

1414
impl BrotliEncoder {
15-
pub(crate) fn new(params: BrotliEncoderParams) -> Self {
15+
pub fn new(params: EncoderParams) -> Self {
16+
let params = BrotliEncoderParams::from(params);
1617
let mut state = BrotliEncoderStateStruct::new(StandardAlloc::default());
1718
state.params = params;
1819
Self { state }
@@ -25,7 +26,7 @@ impl BrotliEncoder {
2526
op: BrotliEncoderOperation,
2627
) -> io::Result<()> {
2728
let in_buf = input.unwritten();
28-
let mut out_buf = output.unwritten_mut();
29+
let out_buf = output.unwritten_mut();
2930

3031
let mut input_len = 0;
3132
let mut output_len = 0;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod decoder;
2+
mod encoder;
3+
pub mod params;
4+
5+
pub use self::{decoder::BrotliDecoder, encoder::BrotliEncoder};

0 commit comments

Comments
 (0)