A closer to the spec implementation of ZIP parsing for Java.
The notes and structure outlines are the basis for most of LLJ-ZIP.
The JVM zip reader implementation is based off this piece.
This is a zip format reader for seekable files, that tolerates leading and trailing garbage, and tolerates having had internal offsets adjusted for leading garbage (as with Info-Zip's zip -A).
But that's not all it does. That's just what that one comment says. Some other fun quirks of the JVM zip parser:
- The end central directory entry is found by scanning from the end of the file, rather than from the beginning.
- The central directory values are authoritative. Names/values defined by the local file headers are ignored.
- The file data of local file headers is not size bound by the file header's compressed size field. Instead, it uses the central directory header's declared size.
- Class names are allowed to end in trailing
/which most tools interpret as directories.
- Reads ZIP files using Unsafe backed mapped files.
- Using
FileChannel.mapyieldsMappedByteBufferwhich usesintvalues, limiting files up to about 2GB - Our
UnsafeMappedFileimplementation useslongwhich far exceeds the GB file size range
- Using
- Highly configurable, offering 3 ZIP reading strategies out of the box (See
ZipIOfor convenience calls)- Std / Forward scanning: Scans for
EndOfCentralDirectoryfrom the front of the file, like many other tools - Naive: Scans only for
LocalFileHeadervalues from the front of the file, the fastest implementation, but obviously naive - JVM: Matches the behavior of the JVM's ZIP parser, including a number of odd edge cases. Useful for opening JAR files to mirror
java -jar <path>behavior.
- Std / Forward scanning: Scans for
Maven dependency:
<dependency>
<groupId>software.coley</groupId>
<artifactId>lljzip</artifactId>
<version>${zipVersion}</version> <!-- See release page for latest version -->
</dependency>Gradle dependency:
implementation group: 'software.coley', name: 'lljzip', version: zipVersion
implementation "software.coley:lljzip:${zipVersion}"For example usage see the tests.
Due to some sun.misc.Unsafe hacks (For performance and long addressing), you will get compiler warnings when first opening the project in IntelliJ.
You can resolve this by changing the compiler target:
