Zipflinger is a library dedicated to ZIP files manipulation. It is capable of adding and removing entries without decompressing/compressing the whole archive. It supports:
Deleting a non-existing entry will fail silently. Adding an existing entry will not silently overwrite but will throw an exception instead.
Map<String, Entry> map = ZipArchive.listEntries(new File("/path/to/zip")); for(Entry entry : map.getEntries().values()) { entry.getName(); entry.getCrc(); ... }
ZipArchive zip = new ZipArchive("app.apk"); zip.delete("classes18.dex"); // All deletes must be submitted first. zip.add(new BytesSource(new File("classes18.dex"), "classes18.dex", Deflater.BEST_SPEED)); zip.add(new BytesSource(new File("img.png"), "image.png", Deflater.NO_COMPRESSION)); zip.close();
ZipArchive zip = new ZipArchive("app.apk"); ZipSource zipSource1 = ZipSource.selectAll(new File("/path/to/zip1.zip")): zip.add(zipSource1); ZipSource zipSource2 = ZipSource.selectAll(new File("/path/to/zip2.zip")): zip.add(zipSource2); zip.close();
ZipArchive zip = new ZipArchive("app.apk"); ZipSource zipSource = new ZipSource(new File("/path/to/zip1.zip")): zipSource.select("classes18.dex", "classes18NewName.dex"); // non-aligned (default) ZipSourceEntry alignedEntry = zipSource.select("lib.so", "lib.so"); // aligned alignedEntry.align(4); zip.addZipSource(zipSource); zip.close();
ZipArchive zip = new ZipArchive("app.apk"); ZipSource zipSource = new ZipSource(new File("/path/to/zip1.zip")): for(String name : zipSource.entries().keys()) { if (youwantIt) { zipSource.select(name, "newName"); } } zip.add(zipSource); zip.close();