Skip to content

zipalign implemented as a java library with 0 deps

License

Notifications You must be signed in to change notification settings

cr4zyserb/zipalign-java

 
 

Repository files navigation

zipalign-java

Zipalign implemented in java without any dependencies. Read my post about it :>

Using

Pass in a RandomAccessFile to the function ZipAlign#alignZip to provide ZipAlign with a seekable file for more performant aligning.

import com.iyxan23.zipalignjava.ZipAlign;

RandomAccessFile zipIn = new RandomAccessFile(zipPath, "r");
FileOutputStream zipOut = ...;

ZipAlign.alignZip(zipIn, zipOut);

Additionaly, you could use a regular InputStream.

import com.iyxan23.zipalignjava.ZipAlign;

FileInputStream zipIn = ...;
FileOutputStream zipOut = ...;

ZipAlign.alignZip(zipIn, zipOut);

Aligning .so files to 4KiB page boundaries are enabled by default, pass in a boolean to opt out:

ZipAlign.alignZip(zipIn, zipOut, false);

Importing

This library is published in jitpack, you can add it as your dependency it with:

allprojects {
    repositories {
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    implementation 'com.github.iyxan23:zipalign-java:1.1.1'
}

You could also use prebuilt jars by the CI or in the releases section.

The jar contains a simple CLI that allows you to use it in the command line.

$ java -jar zipalign-java-1.1.1.jar input.zip output.zip

Benchmarks

Benchmarks are ran on an AMD Ryzen 5-5500U CPU with IntelliJ IDEA's runner and Temurin JDK 18.

Function                                             Avg elapsed time   Input

ZipAlign#alignZip(RandomAccessFile, OutputStream)    28ms               File from https://github.com/Iyxan23/zipalign-java/issues/1#issue-1236875761 (270K)
ZipAlign#alignZip(InputStream, OutputStream)         497ms              -- same file --

About

zipalign implemented as a java library with 0 deps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%