Skip to content

Commit

Permalink
#107 Check and update all LFH offsets when removing files from zip
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Nov 24, 2019
1 parent 20bd0b7 commit c41e2fa
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void updateHeaders(ZipModel zipModel, SplitOutputStream splitOutputStrea
updateEndOfCentralDirectoryRecord(zipModel, splitOutputStream);
zipModel.getCentralDirectory().getFileHeaders().remove(indexOfFileHeader);
updateFileHeadersWithLocalHeaderOffsets(zipModel.getCentralDirectory().getFileHeaders(), offsetEndOfCompressedFile,
offsetLocalFileHeader, indexOfFileHeader);
offsetLocalFileHeader);

HeaderWriter headerWriter = new HeaderWriter();
headerWriter.finalizeZipFile(zipModel, splitOutputStream, charset);
Expand All @@ -145,14 +145,18 @@ private void updateEndOfCentralDirectoryRecord(ZipModel zipModel, SplitOutputStr
}

private void updateFileHeadersWithLocalHeaderOffsets(List<FileHeader> fileHeaders, long offsetEndOfCompressedFile,
long offsetLocalFileHeader, int indexOfFileHeader) {
for (int i = indexOfFileHeader; i < fileHeaders.size(); i ++) {
long offsetLocalFileHeader) {
for (int i = 0; i < fileHeaders.size(); i ++) {
FileHeader fileHeader = fileHeaders.get(i);
long offsetLocalHdr = fileHeader.getOffsetLocalHeader();

if (fileHeader.getZip64ExtendedInfo() != null && fileHeader.getZip64ExtendedInfo().getOffsetLocalHeader() != -1) {
offsetLocalHdr = fileHeader.getZip64ExtendedInfo().getOffsetLocalHeader();
}
fileHeader.setOffsetLocalHeader(offsetLocalHdr - (offsetEndOfCompressedFile - offsetLocalFileHeader) - 1);

if (offsetLocalHdr > offsetLocalFileHeader) {
fileHeader.setOffsetLocalHeader(offsetLocalHdr - (offsetEndOfCompressedFile - offsetLocalFileHeader) - 1);
}
}
}

Expand Down

0 comments on commit c41e2fa

Please sign in to comment.