-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#183 fix versionMadeBy and versionNeededToExtract header values
- Loading branch information
1 parent
a4745ca
commit 76db682
Showing
13 changed files
with
308 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/net/lingala/zip4j/headers/VersionMadeBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.lingala.zip4j.headers; | ||
|
||
public enum VersionMadeBy { | ||
|
||
SPECIFICATION_VERSION((byte) 51), | ||
WINDOWS((byte) 0), | ||
UNIX((byte) 3); | ||
|
||
private byte code; | ||
|
||
VersionMadeBy(byte code) { | ||
this.code = code; | ||
} | ||
|
||
public byte getCode() { | ||
return code; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/net/lingala/zip4j/headers/VersionNeededToExtract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.lingala.zip4j.headers; | ||
|
||
public enum VersionNeededToExtract { | ||
|
||
DEFAULT(10), | ||
DEFLATE_COMPRESSED(20), | ||
ZIP_64_FORMAT(45), | ||
AES_ENCRYPTED(51); | ||
|
||
private int code; | ||
|
||
VersionNeededToExtract(int code) { | ||
this.code = code; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.lingala.zip4j.util; | ||
|
||
import net.lingala.zip4j.headers.VersionMadeBy; | ||
import net.lingala.zip4j.headers.VersionNeededToExtract; | ||
import net.lingala.zip4j.model.ZipParameters; | ||
import net.lingala.zip4j.model.enums.CompressionMethod; | ||
import net.lingala.zip4j.model.enums.EncryptionMethod; | ||
|
||
public class ZipVersionUtils { | ||
|
||
public static int determineVersionMadeBy(ZipParameters zipParameters, RawIO rawIO) { | ||
byte[] versionMadeBy = new byte[2]; | ||
versionMadeBy[0] = VersionMadeBy.SPECIFICATION_VERSION.getCode(); | ||
versionMadeBy[1] = VersionMadeBy.UNIX.getCode(); | ||
if (FileUtils.isWindows() && !zipParameters.isUnixMode()) { // skip setting windows mode if unix mode is forced | ||
versionMadeBy[1] = VersionMadeBy.WINDOWS.getCode(); | ||
} | ||
|
||
return rawIO.readShortLittleEndian(versionMadeBy, 0); | ||
} | ||
|
||
public static VersionNeededToExtract determineVersionNeededToExtract(ZipParameters zipParameters) { | ||
VersionNeededToExtract versionRequired = VersionNeededToExtract.DEFAULT; | ||
|
||
if (zipParameters.getCompressionMethod() == CompressionMethod.DEFLATE) { | ||
versionRequired = VersionNeededToExtract.DEFLATE_COMPRESSED; | ||
} | ||
|
||
if (zipParameters.getEntrySize() > InternalZipConstants.ZIP_64_SIZE_LIMIT) { | ||
versionRequired = VersionNeededToExtract.ZIP_64_FORMAT; | ||
} | ||
|
||
if (zipParameters.isEncryptFiles() && zipParameters.getEncryptionMethod().equals(EncryptionMethod.AES)) { | ||
versionRequired = VersionNeededToExtract.AES_ENCRYPTED; | ||
} | ||
|
||
return versionRequired; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.