summaryrefslogtreecommitdiffstats
path: root/tools/zipalign/ZipAlign.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/zipalign/ZipAlign.cpp')
-rw-r--r--tools/zipalign/ZipAlign.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/tools/zipalign/ZipAlign.cpp b/tools/zipalign/ZipAlign.cpp
index 8b2d1af..dc2826b 100644
--- a/tools/zipalign/ZipAlign.cpp
+++ b/tools/zipalign/ZipAlign.cpp
@@ -32,19 +32,20 @@ void usage(void)
fprintf(stderr, "Zip alignment utility\n");
fprintf(stderr, "Copyright (C) 2009 The Android Open Source Project\n\n");
fprintf(stderr,
- "Usage: zipalign [-f] [-v] <align> infile.zip outfile.zip\n"
+ "Usage: zipalign [-f] [-v] [-z] <align> infile.zip outfile.zip\n"
" zipalign -c [-v] <align> infile.zip\n\n" );
fprintf(stderr,
" <align>: alignment in bytes, e.g. '4' provides 32-bit alignment\n");
fprintf(stderr, " -c: check alignment only (does not modify file)\n");
fprintf(stderr, " -f: overwrite existing outfile.zip\n");
fprintf(stderr, " -v: verbose output\n");
+ fprintf(stderr, " -z: recompress using Zopfli\n");
}
/*
* Copy all entries from "pZin" to "pZout", aligning as needed.
*/
-static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment)
+static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfli)
{
int numEntries = pZin->getNumEntries();
ZipEntry* pEntry;
@@ -67,6 +68,12 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment)
// pEntry->getFileName(), (long) pEntry->getFileOffset(),
// (long) pEntry->getUncompressedLen());
+ if (zopfli) {
+ status = pZout->addRecompress(pZin, pEntry, &pNewEntry);
+ bias += pNewEntry->getCompressedLen() - pEntry->getCompressedLen();
+ } else {
+ status = pZout->add(pZin, pEntry, padding, &pNewEntry);
+ }
} else {
/*
* Copy the entry, adjusting as required. We assume that the
@@ -79,9 +86,9 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment)
//printf("--- %s: orig at %ld(+%d) len=%ld, adding pad=%d\n",
// pEntry->getFileName(), (long) pEntry->getFileOffset(),
// bias, (long) pEntry->getUncompressedLen(), padding);
+ status = pZout->add(pZin, pEntry, padding, &pNewEntry);
}
- status = pZout->add(pZin, pEntry, padding, &pNewEntry);
if (status != NO_ERROR)
return 1;
bias += padding;
@@ -98,7 +105,7 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment)
* output file exists and "force" wasn't specified.
*/
static int process(const char* inFileName, const char* outFileName,
- int alignment, bool force)
+ int alignment, bool force, bool zopfli)
{
ZipFile zin, zout;
@@ -129,7 +136,7 @@ static int process(const char* inFileName, const char* outFileName,
return 1;
}
- int result = copyAndAlign(&zin, &zout, alignment);
+ int result = copyAndAlign(&zin, &zout, alignment, zopfli);
if (result != 0) {
printf("zipalign: failed rewriting '%s' to '%s'\n",
inFileName, outFileName);
@@ -196,6 +203,7 @@ int main(int argc, char* const argv[])
bool check = false;
bool force = false;
bool verbose = false;
+ bool zopfli = false;
int result = 1;
int alignment;
char* endp;
@@ -222,6 +230,9 @@ int main(int argc, char* const argv[])
case 'v':
verbose = true;
break;
+ case 'z':
+ zopfli = true;
+ break;
default:
fprintf(stderr, "ERROR: unknown flag -%c\n", *cp);
wantUsage = true;
@@ -252,7 +263,7 @@ int main(int argc, char* const argv[])
result = verify(argv[1], alignment, verbose);
} else {
/* create the new archive */
- result = process(argv[1], argv[2], alignment, force);
+ result = process(argv[1], argv[2], alignment, force, zopfli);
/* trust, but verify */
if (result == 0)