srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2.01k stars 307 forks source link

split zip files can not extract single file correctly #459

Closed lzxshare closed 1 year ago

lzxshare commented 1 year ago
because i have many files,i split the zip file,like this:

ZipParameters zipParameters = new ZipParameters();
zipParameters.setEncryptFiles(true);
zipParameters.setCompressionLevel(CompressionLevel.FAST);
zipParameters.setIncludeRootFolder(false);
zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_AND_LINKED_FILE);
zipParameters.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD);  

ZipFile zipFile = new ZipFile(packOutputFile, keyword.toCharArray());
zipFile.setRunInThread(true);
zipFile.createSplitZipFile(backFileList, defaultZipParameters, true, SPLIT_SIZE);

some files has the same file name,but from different path:

A/B/C/fileName.txt
A/F/G/fileName.txt
A/B/C/P/fileName.txt
E/B/C/fileName.txt
....

i want to extract single file,like A/B/C/P/fileName.txt,and i use this api code:

FileHeader fileHeader = zipFile.getFileHeader("fileName.txt"); zipFile.extractFile(fileHeader, parentFile.getAbsolutePath(), mergeName);

but i got a not correct file.i also use the full path to get FileHeader:

FileHeader fileHeader = zipFile.getFileHeader("A/B/C/P/fileName.tx"); zipFile.extractFile(fileHeader, parentFile.getAbsolutePath(), mergeName);

but they returns null,i also debug the source code,and i found Zip FileHeader only show file names,debug info like this:

image

note: the parameters passed "backFileList" all is the files, not contains folder

and here is output zip file,the encryption password is 111111,you can input password to unzip the test file.

could you give me some helpful ideas?this question has puzzled me for a long time, and i want to solve it as soon as possible. thank you very much.

1658803896900.zip

srikanth-lingala commented 1 year ago

zipFile.createSplitZipFile works at a file level and does not preserve the folder. To preserve folder structure, you have to use zipFile.createSplitZipFileFromFolder.