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

Create fs2.compression.checksum #2606

Merged
merged 8 commits into from
Sep 29, 2021
Merged

Conversation

armanbilge
Copy link
Member

Creates a new fs.compression.Checksum[F] trait which so far provides the CRC32 algorithm. This is used for example in http4s compression middleware.

The JVM implementation uses java.util.zip.CRC32. The JS implementation is kindly provided by means of Kafka. It's worth noting that they reimplemented CRC32 in Java for performance reasons, and since we've already ported the code here we may as well consider using it on the JVM as well.

@mpilquist
Copy link
Member

Note this is built in to scodec-bits: http://scodec.org/api/scodec-bits/1.1.0/scodec/bits/crc$.html

@armanbilge
Copy link
Member Author

Oops! Lets see where that gets us.

@armanbilge
Copy link
Member Author

Does the scodec-bits implementation support streaming? If so, it's not obvious to me how it can be used here.

@armanbilge
Copy link
Member Author

Ahh, it's a linear function. So actually, we don't need any of this, do we?

@armanbilge armanbilge closed this Sep 11, 2021
@armanbilge
Copy link
Member Author

Reopening, now that I've done my homework. CRC32's can be combined due to their linearity, but implementing this is fairly involved and would not be as performant. See this in zlib.

Interestingly, the CRC32 implementation I've ported here was mentioned in scodec/scodec-bits@d69a425#r18797902.

Thoughts?

@armanbilge armanbilge reopened this Sep 11, 2021
@mpilquist
Copy link
Member

Couple thoughts:

  • It would be nice to allow the codec-bits crc code to be used in a streaming fashion (via a builder pattern -- create, add bit vectors, and then finalize when done)
  • The fs2.hash object takes a different stylistic approach, supporting arbitrary effect types (not requiring Sync)

@armanbilge
Copy link
Member Author

Makes sense, thanks. Fix (1) in scodec-bits, everything becomes easier here and we should get (2) for free :) Now if I can muster up the courage to poke at that code 😅

@armanbilge armanbilge marked this pull request as draft September 11, 2021 19:35
@armanbilge armanbilge marked this pull request as ready for review September 28, 2021 18:43
@armanbilge
Copy link
Member Author

Updated to use the new builder from scodec/scodec-bits#316. I followed the style of fs2.hash which made things much nicer all around.

@armanbilge armanbilge changed the title Create Checksum[F] and implement CRC32 checksum Create fs2.compression.checksum Sep 28, 2021
@mpilquist mpilquist merged commit 7f7e165 into typelevel:main Sep 29, 2021
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