Skip to content

Implement gunzip function for GZIP decompression#417

Closed
staging-devin-ai-integration[bot] wants to merge 1 commit intomainfrom
core-imple-79b26e5a
Closed

Implement gunzip function for GZIP decompression#417
staging-devin-ai-integration[bot] wants to merge 1 commit intomainfrom
core-imple-79b26e5a

Conversation

@staging-devin-ai-integration
Copy link
Copy Markdown

Implement gunzip function for GZIP decompression

Summary

Adds a new gunzip function that decompresses GZIP-compressed input streams into strings. The function takes std::istream &stream as input and returns std::optional<std::string>, following the same pattern and error handling approach as the existing gzip compression function.

Key changes:

  • Added gunzip function declaration to header with comprehensive documentation and usage example
  • Implemented stream-based decompression using zlib's inflate functions as counterpart to existing deflate usage
  • Added 4 comprehensive test cases covering basic decompression, round-trip testing, invalid data handling, and empty stream handling
  • Uses same 4096-byte buffer size and error handling patterns as existing gzip function

Review & Testing Checklist for Human

This is a medium-risk change due to low-level zlib usage and stream handling complexity. Please verify:

  • Stream handling correctness: Test the function with various sizes of compressed data (small, large, multi-chunk) to ensure the stream reading loop handles partial reads and buffer boundaries correctly
  • Error handling robustness: Try feeding malformed/corrupted GZIP data to verify all error paths return std::nullopt appropriately and don't crash or leak memory
  • Round-trip compatibility: Verify that data compressed with the existing gzip function can be reliably decompressed with gunzip across different data types and sizes
  • Resource management: Check for memory leaks by running tests under valgrind or similar tool, especially focusing on error paths where inflateEnd() must be called

Test Plan Recommendation

// Test with your own data beyond the unit tests
const std::string test_data = "Your test data here...";
const auto compressed = sourcemeta::core::gzip(test_data);
std::istringstream stream(compressed.value());
const auto result = sourcemeta::core::gunzip(stream);
assert(result.value() == test_data);

Notes

  • Implementation mirrors the existing gzip function structure using zlib's inflate functions instead of deflate
  • Added has_data flag to properly handle empty stream case (this was needed to fix failing tests)
  • All error conditions return std::nullopt following the existing pattern
  • Link to Devin run: https://staging.itsdev.in/sessions/72d4a78026d24b5e9dbd4009e1c3b035
  • Requested by: Juan Cruz Viotti (@jviotti)

- Add gunzip function that takes std::istream and returns std::optional<std::string>
- Function decompresses GZIP-compressed streams using zlib inflate functions
- Add comprehensive tests including round-trip compression/decompression
- Add error handling for invalid data and empty streams
- Follow existing code patterns and documentation style

Co-Authored-By: Juan Cruz Viotti <jv@jviotti.com>
@staging-devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@staging-devin-ai-integration
Copy link
Copy Markdown
Author

Closing due to inactivity for more than 7 days. Configure here.

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.

0 participants