Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ZlibCompressor/Decompressor #10

Merged
merged 7 commits into from
Oct 25, 2024
Merged

Expose ZlibCompressor/Decompressor #10

merged 7 commits into from
Oct 25, 2024

Conversation

adam-fowler
Copy link
Owner

@adam-fowler adam-fowler commented Oct 19, 2024

This PR

  • Makes ZlibCompressor/Decompressor non-copyable types (They hold mutable buffers generated by a C library). Doing this allows us to tag them as Sendable.
  • Makes ZlibCompressor/Decompressor public
  • Adds ByteBuffer methods that use the ZlibCompressor/Decompressor directly
  • Add wrapper types that wrap the new types and conform to NIOCompressor/Decompressor to ensure we using the same code path whether we use NIO or Zlib types.
  • Add tests that use new concrete types.
  • Deprecate NIOCompressor/Decompressor and related functions in favour of the Zlib versions. The NIO prefixed versions are unnecessary existentials and it is preferable to use the concrete Zlib versions.

/// - flush: how compressor should flush output data.
/// - process: Closure to be called when window buffer fills up or compress has finished
/// - Returns: `ByteBuffer` containing compressed data
public mutating func compressStream(
Copy link

Choose a reason for hiding this comment

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

Can we make this work with an AsyncSequence as in- and/or output?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I can review some of the APIs but as the Compressor is non-copyable we have to be clearer about who owns it. So using it in an AsyncSequence is problematic. Eg I have a compressor I want to re-use, if I create an AsyncSequence that takes ownership of it there is no easy to pass it back once iteration has completed.

Copy link

Choose a reason for hiding this comment

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

Hmm, unfortunate.

Also clean up interface so when they are allocated they are active already, instead of having non-initialized state
@adam-fowler adam-fowler requested a review from Joannis October 21, 2024 15:22
@adam-fowler adam-fowler changed the title Expose ZlibCompressor and make it non-Copyable Expose ZlibCompressor/Decompressor Oct 22, 2024
@adam-fowler adam-fowler merged commit 9dedf2c into main Oct 25, 2024
5 checks passed
@adam-fowler adam-fowler deleted the zlib-non-copyable branch October 25, 2024 09:39
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.

2 participants