iyxan23 / zipalign-java

zipalign implemented as a java library with 0 deps
MIT License
53 stars 13 forks source link

Ideas for the next 2.0.0 #7

Open iyxan23 opened 9 months ago

iyxan23 commented 9 months ago

The current API of zipalign is very minimal and a bit too specific (the RandomAccessFile arg). Honestly the original API looks good as-is, and is perfect for its main goal but its a bit hard to maintain the long lines of code. I'm imagining a more object-oriented approach in the next 2.0.0 so it could be called a "real" library :smile:

I'm thinking of an API that will look something like this:

ZipAnalyzer analyzer = new ZipAnalyzer("./file.zip");
// or 
ZipAnalyzer analyzer = new ZipAnalyzer(new FileInputStream(...));
// or maybe even
byte[] something = new byte[...];
ZipAnalyzer analyzer = new ZipAnalyzer(something);

analyzer.setAlignSoFiles(true, 4096);
analyzer.specialCase(new AlignCase() { ... }, 16); // perhaps the user wanted to align something specific? X)

Alignments alignments = analyzer.analyze();
alignments.align("./file.zip", "output.zip");
alignments.align(new FileInputStream(...), "output.zip");
alignments.alignInPlace("./file.zip");
byte[] result = alignments.alignToBytes("./file.zip");

What do you think?