Skip to content

Commit

Permalink
Compare the asset apk with extracted apk by their size
Browse files Browse the repository at this point in the history
  • Loading branch information
galenlin committed Jan 17, 2017
1 parent a5401dd commit 9c47eae
Showing 1 changed file with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,27 +462,16 @@ private void extractBundle(String assetName, File outFile) throws IOException {
InputStream in = Small.getContext().getAssets().open(assetName);
FileOutputStream out;
if (outFile.exists()) {
// Compare the zip time to see if needs re-extract.
// @see https://en.wikipedia.org/wiki/Zip_(file_format)
// Compare the two input steams to see if needs re-extract.
FileInputStream fin = new FileInputStream(outFile);
final int headerSizeBeforeTime = 10;
final int headerSizeOfTime = 4;
byte[] inHeader = new byte[headerSizeBeforeTime];
byte[] inTime = new byte[headerSizeOfTime];
byte[] outTime = new byte[headerSizeOfTime];
in.read(inHeader);
in.read(inTime);
fin.skip(headerSizeBeforeTime);
fin.read(outTime);
fin.close();
if (Arrays.equals(inTime, outTime)) {
in.close();
int inSize = in.available();
long outSize = fin.available();
if (inSize == outSize) {
// FIXME: What about the size is same but the content is different?
return; // UP-TO-DATE
}

out = new FileOutputStream(outFile);
out.write(inHeader, 0, headerSizeBeforeTime);
out.write(inTime, 0, headerSizeOfTime);
} else {
out = new FileOutputStream(outFile);
}
Expand Down

0 comments on commit 9c47eae

Please sign in to comment.