Skip to content

Conversation

@folkertdev
Copy link
Contributor

This is an initial design for using the zlib_rs API, calling the safe functions that it exposes rather than the unsafe wrappers of libz-rs-sys.

I'm designing the flate2 side here, the actual implementation still uses libz-rs-sys because zlib-rs does not export some things that we need here.

Inspired by GitoxideLabs/gitoxide#2155.

@folkertdev folkertdev force-pushed the zlib-rs-api branch 2 times, most recently from 46ea2c4 to 32a775b Compare November 11, 2025 21:28
@folkertdev folkertdev force-pushed the zlib-rs-api branch 2 times, most recently from d34a7b8 to af1615e Compare November 25, 2025 14:06
@folkertdev
Copy link
Contributor Author

@Byron I think this is ready now in terms of what the code looks like. Could you give this a once-over to see that it looks allright from an API perspective? Then we'll release zlib-rs and we can merge this.

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much, this looks fantastic.

It seems that integrating zlib-rs natively is very straightforward, and I'd live to see this PR merged.

So I am looking forward to doing that, just let me know.

@@ -0,0 +1,164 @@
//! Implementation for `zlib_rs` rust backend.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would help me here is a quick idea of why this module exports what it exports. My guess is that these types are used to integrate with flate2, and it expects these primitives to exist and implemented by each backend.

It's probably stating the obvious then 😅, and maybe there can be more in-depth information on what makes this module a little bit special even. Are there implications for allocations? Does it allocate? I guess I'd be happy to ready about everything you were thinking at the time of writing so it's conserved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote some things but yeah generally it's just the most bare-bones thing that satisfies the assumptions that are made about a backend.

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely fantastic, and thanks for these wonderful docs 🙏.

Comment on lines +3 to +18
//! Every backend must provide two types:
//!
//! - `Deflate` for compression, implements the `Backend` and `DeflateBackend` trait
//! - `Inflate` for decompression, implements the `Backend` and `InflateBackend` trait
//!
//! Additionally the backend provides a number of constants, and a `ErrorMessage` type.
//!
//! ## Allocation
//!
//! The (de)compression state is not boxed. The C implementations require that the z_stream is
//! pinned in memory (has a fixed address), because their z_stream is self-referential. The most
//! convenient way in rust to guarantee a stable address is to `Box` the data, but it does add an
//! additional allocation.
//!
//! With zlib_rs the state is not self-referential and hence no boxing is needed. The `new` methods
//! internally do allocate space for the (de)compression state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely! This gives me the background about some fundamentals of the crate that I should have obtained years ago 😅.

@Byron Byron marked this pull request as ready for review November 27, 2025 06:03
@Byron Byron marked this pull request as draft November 27, 2025 06:03
@Byron
Copy link
Member

Byron commented Nov 27, 2025

Oh wow, I was close to merging this.
But we don't as I wait for your cue when zlib-rs is re-released.

Let's put the update in a separate commit as well please, it's easier to review if we stop rewriting now.

@folkertdev folkertdev marked this pull request as ready for review December 3, 2025 14:01
@folkertdev
Copy link
Contributor Author

We've released 0.5.3, containing the stable API. This is ready to merge now, and if there are no issues we can make it the default implementation.

@folkertdev
Copy link
Contributor Author

Let's put the update in a separate commit as well please, it's easier to review if we stop rewriting now.

I missed that. What do you mean with the update? just the Cargo.toml changes?

@Byron
Copy link
Member

Byron commented Dec 3, 2025

Sorry, I mean to ask to not force-push anymore as I have to re-review everything in the worst case. Which might have happened.

Besides that, I am glad this will be ready. And a version bump to Cargo.toml would definitely help with the release.

fn make(level: Compression, zlib_header: bool, _window_bits: u8) -> Self {
// Check in case the integer value changes at some point.
debug_assert!(level.level() <= 10);
debug_assert!(level.level() <= 9);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary? miniz_oxide supports level 10 according to its docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I had assumed that it was a typo. Let me fix that then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants