Skip to content

Conversation

@n2k
Copy link

@n2k n2k commented Nov 13, 2025

This PR adds comprehensive support for extracting multi-volume RAR archives (split archives with .rar, .r00, .r01, etc. naming convention).

Key Changes

  • Multi-volume stream handler: Implements a custom C-based multivolume stream handler (stream-multivolume.c) that seamlessly reads across multiple physical volume files
  • Volume boundary handling: Adds rar_continue_volume() to parse RAR headers at volume boundaries and correctly track data segments across volumes
  • Extraction support: Modifies rar_copy_stored() and br_fill() to handle volume transitions during extraction of both stored and compressed files
  • Go API: Adds OpenMultivolume() function in the Go wrapper to detect and open multi-volume RAR archives
  • Volume naming: Supports up to 900 volumes with proper naming convention:
    • .rar (first volume)
    • .r00-.r99 (volumes 0-99)
    • .s00-.s99 (volumes 100-199)
    • .t00-.t99 (volumes 200-299)
    • Continuing through alphabet to .z00-.z99 (volumes 800-899)

Testing

  • Added comprehensive unit tests for volume path naming logic (26 tests covering edge cases and boundaries)
  • Added TestMultiVolumeRar() integration test that validates extraction from multi-volume RAR archives
  • Includes test helper function TestGetVolumePath for testing volume naming
  • All existing tests pass

Documentation

  • Updated README with multi-volume feature documentation
  • Added code example showing how to extract multi-volume archives
  • Added testing instructions for multi-volume archives

Test plan

  • Run go test -v to verify all existing tests pass
  • Create a multi-volume RAR archive and test extraction
  • Verify volume naming works correctly for volumes 0-899
  • Test extraction of files that span multiple volumes
  • Verify graceful fallback to single-file streams when needed

n2k added 3 commits November 13, 2025 20:46
Implements support for extracting multi-volume RAR archives (split
archives with .rar, .r00, .r01, etc. naming convention).

Changes:
- Add custom multivolume stream handler (stream-multivolume.c) that
  seamlessly reads across multiple physical volume files
- Implement rar_continue_volume() to parse headers at volume boundaries
  and correctly track data segments across volumes
- Modify rar_copy_stored() and br_fill() to handle volume transitions
  during extraction
- Add OpenMultivolume() function in Go wrapper to detect and open RAR
  archives using the multivolume stream
- Add TestMultiVolumeRar() test that validates extraction from any
  multi-volume RAR in testdata/multivolume/ directory
- Update README with feature documentation and testing instructions

The implementation correctly handles:
- Reading data that spans multiple volume files
- Parsing RAR headers at volume boundaries (signature, main header,
  file entry headers)
- Extracting both stored and compressed files from multi-volume archives
- Gracefully falling back to single-file streams when needed

All existing tests pass, and multi-volume extraction is verified to
produce correct output matching reference files.
Enhanced volume naming to support archives spanning hundreds of files:
- .rar (first volume)
- .r00-.r99 (volumes 0-99)
- .s00-.s99 (volumes 100-199)
- .t00-.t99 (volumes 200-299)
- continuing through alphabet to .z99 (up to 2600 total volumes)

Updated documentation and comments to reflect extended support.
Corrected the maximum volume limit from 2599 to 899 (.z99) as the
alphabet only spans r-z (9 letters × 100 volumes each).

Changes:
- Fixed volume naming to properly support .r00-.r99, .s00-.s99, through .z00-.z99
- Updated safety limit from 2599 to 899 in multivolume_seek
- Added comprehensive unit tests for volume path naming
- Added test helper function TestGetVolumePath for testing volume naming logic
- Tests cover all edge cases, boundaries, and alphabet coverage
- All 26 tests pass successfully

This ensures archives can span up to 900 volumes correctly.
@gen2brain
Copy link
Owner

Nice, thanks! I need to find a time to test it. And I would prefer if AI did not mess with the README, i.e., **Multi-volume RAR archive support** (.rar, .r00-.r99, .s00-.s99, .t00-.t99, .u00-.u99, .v00-.v99, .w00-.w99, .x00-.x99, .y00-.y99, .z00-.z99). Why would someone care about all these, if someone wants can take a look at the code or tests. It's not for README. Also, I do not like how the C test has bindings and is exported only to be called in the Go test. That looks strange. However, all these are nitpicks; I can review them later, but the feature is very nice! If you have time and are interested, RAR5 support would be VERY NICE to have.

@n2k n2k closed this Nov 17, 2025
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