Skip to content

Add Adler32, Crc32, and Deflate APIs - #86

Merged
Tyrrrz merged 10 commits into
primefrom
copilot/add-hashing-and-deflate-apis
Jul 13, 2026
Merged

Add Adler32, Crc32, and Deflate APIs#86
Tyrrrz merged 10 commits into
primefrom
copilot/add-hashing-and-deflate-apis

Conversation

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Adds three new static utility classes for checksum computation and Deflate compression.

New APIs

  • Adler32.Hash(Stream) / Adler32.Hash(byte[]) / Adler32.Hash(ReadOnlySpan<byte>)uint
  • Crc32.Hash(Stream) / Crc32.Hash(byte[]) / Crc32.Hash(ReadOnlySpan<byte>)uint (IEEE 802.3 / 0xEDB88320 polynomial)
  • Deflate.Compress(Stream, Stream) / Deflate.Compress(byte[]) / Deflate.Compress(ReadOnlySpan<byte>)void / byte[]
  • Deflate.Decompress(Stream, Stream) / Deflate.Decompress(byte[]) / Deflate.Decompress(ReadOnlySpan<byte>)void / byte[]
uint checksum = Adler32.Hash("Wikipedia"u8);       // 0x11E60398
uint crc      = Crc32.Hash("123456789"u8);         // 0xCBF43926

byte[] compressed   = Deflate.Compress(data);
byte[] decompressed = Deflate.Decompress(compressed);

// Stream-based API
using var input  = File.OpenRead("data.bin");
using var output = File.Create("data.deflate");
Deflate.Compress(input, output);

Implementation notes

  • Stream overloads are the primary implementations for all three classes.
  • byte[] overloads delegate to the Stream overloads via MemoryStream.
  • ReadOnlySpan<byte> overloads are guarded with #if !NETFRAMEWORK || NET45_OR_GREATER (consistent with existing Span usage; System.Memory is not available for net35). Adler32 and Crc32 span overloads compute directly over the span to avoid an intermediate array allocation; Deflate span overloads delegate via .ToArray().
  • Crc32 uses a pre-computed 256-entry lookup table initialized once at startup.

@Tyrrrz Tyrrrz added the enhancement New feature or request label Jul 11, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review July 11, 2026 19:19
Copilot AI review requested due to automatic review settings July 11, 2026 19:19
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.20%. Comparing base (96a1e2a) to head (c69f84d).
⚠️ Report is 1 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #86      +/-   ##
==========================================
+ Coverage   85.45%   86.20%   +0.75%     
==========================================
  Files          71       74       +3     
  Lines        1176     1240      +64     
  Branches      218      229      +11     
==========================================
+ Hits         1005     1069      +64     
  Misses        121      121              
  Partials       50       50              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tyrrrz Tyrrrz changed the title feat: add Adler32, Crc32, and Deflate APIs Add Adler32, Crc32, and Deflate APIs Jul 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces three new utility APIs in PowerKit for common binary operations: Adler-32, CRC-32 (IEEE 802.3), and Deflate compression/decompression, alongside unit tests to validate expected behavior.

Changes:

  • Added Adler32 and Crc32 static classes with byte[] and ReadOnlySpan<byte> hashing overloads.
  • Added Deflate static class with Compress/Decompress APIs for byte[] and (where available) ReadOnlySpan<byte>.
  • Added test coverage for the new checksum and compression utilities.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
PowerKit/Adler32.cs Adds Adler-32 checksum API with Span + array overloads.
PowerKit/Crc32.cs Adds CRC-32 checksum API with lookup table + Span + array overloads.
PowerKit/Deflate.cs Adds Deflate compression/decompression helpers for arrays and spans (where supported).
PowerKit.Tests/Adler32Tests.cs Validates Adler-32 known vectors and basic invariants.
PowerKit.Tests/Crc32Tests.cs Validates CRC-32 known vectors and basic invariants.
PowerKit.Tests/DeflateTests.cs Validates roundtrip compression/decompression and basic compression behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit/Adler32.cs Outdated
Comment thread PowerKit/Crc32.cs Outdated

@Tyrrrz Tyrrrz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Comment thread PowerKit/Adler32.cs Outdated
Comment thread PowerKit.Tests/Crc32Tests.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Comment thread PowerKit/Crc32.cs Outdated
Comment thread PowerKit/Crc32.cs Outdated
Comment thread PowerKit/Crc32.cs Outdated
Comment thread PowerKit/Adler32.cs Outdated
Comment thread PowerKit/Deflate.cs Outdated
Comment thread PowerKit/Deflate.cs Outdated
Comment thread PowerKit/Deflate.cs Outdated
Comment thread PowerKit/Deflate.cs Outdated
Tyrrrz and others added 2 commits July 13, 2026 13:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Tyrrrz

Tyrrrz commented Jul 13, 2026

Copy link
Copy Markdown
Owner

@copilot do you think we could end Stream overloads for all these methods and delegate byte[] overloads to them via MemoryStream?

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot do you think we could end Stream overloads for all these methods and delegate byte[] overloads to them via MemoryStream?

Yes, done in commit refactor: add Stream overloads as primary, delegate byte[] via MemoryStream.

  • Adler32.Hash(Stream) and Crc32.Hash(Stream) are now the primary implementations (read via a 4 KB buffer loop). Hash(byte[]) wraps in a MemoryStream and delegates.
  • Deflate.Compress(Stream, Stream) and Deflate.Decompress(Stream, Stream) are now the primary implementations. Compress(byte[]) / Decompress(byte[]) wrap their inputs/outputs in MemoryStream and delegate.
  • The ReadOnlySpan<byte> overloads on Adler32/Crc32 still compute directly over the span (no stream overhead), and Deflate's span overloads delegate via ToArray().
  • Added Stream-overload tests for all three classes, plus the previously missing Deflate ReadOnlySpan<byte> round-trip test.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants