Skip to content

feat: improve filename handling in extractAll (custom names & Chinese fix) - #544

Open
nonameShijian wants to merge 5 commits into
srikanth-lingala:masterfrom
nonameShijian:master
Open

feat: improve filename handling in extractAll (custom names & Chinese fix)#544
nonameShijian wants to merge 5 commits into
srikanth-lingala:masterfrom
nonameShijian:master

Conversation

@nonameShijian

@nonameShijian nonameShijian commented May 16, 2024

Copy link
Copy Markdown

This PR enhances ZipFile.extractAll() to better handle real-world ZIP files with non-ASCII (e.g. Chinese) filenames and supports custom output naming.

Changes

  1. Fix "File header and local file header mismatch" for Unicode filenames

    • Now checks the 0x7075 (Info-ZIP Unicode Path) extra field to get the correct UTF-8 filename
    • Uses UTF-8 name for header comparison, avoiding false mismatch errors caused by encoding issues
  2. Support custom output filenames via newFileNameMap

    • Added support to remap original filenames to new names during extraction
    • Example usage:
      Map<String, String> newNames = new HashMap<>();
      newNames.put(fileHeader.getFileName(), "new_name.txt");
      zipFile.extractAll(outputPath, newNames);

Benefits

  • Can now extract ZIPs created on Windows/Chinese systems without errors
  • Allows renaming files during extraction (e.g. avoid conflicts, sanitize names)

This makes extractAll() more robust and user-friendly for international use cases.

Check UTF-8 name in 0x7075 extra field to avoid false "File header and local file header mismatch" error for non-ASCII filenames.
@nonameShijian nonameShijian changed the title add newFileNameMap for zipFile.extractAll feat: improve filename handling in extractAll (custom names & Chinese fix) Sep 3, 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.

1 participant