Skip to content

Commit f2eebe6

Browse files
Merge pull request #62 from usefulness/fix_size_calculation
2 parents d725d84 + a6afb83 commit f2eebe6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

diffuse/src/test/kotlin/com/jakewharton/diffuse/FunctionalTest.kt

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ class FunctionalTest {
4545
assertThat(lines).contains(" - androidx.recyclerview.widget.RecyclerView markItemDecorInsetsDirty():0: RecyclerView\$ItemAnimator")
4646
assertThat(lines[7]).isEqualTo(" dex │ 1 MiB │ 1.2 MiB │ +164.8 KiB │ 2.2 MiB │ 2.6 MiB │ +380.9 KiB ")
4747
}
48+
49+
@Test
50+
internal fun `diffuse diff on aar`() {
51+
val output = anotherTempDir.resolve("diffuse-out")
52+
val aarA = loadResource("lazythreeten/lazythreetenbp-release.aar")
53+
val aarB = loadResource("lazythreeten/lazythreetenbp-release.aar")
54+
55+
main(
56+
"diff",
57+
"--aar", aarA, aarB,
58+
"--text", output.path,
59+
)
60+
61+
assertThat(output.readLines()).contains(" total │ 160.7 KiB │ 160.7 KiB │ 0 B ")
62+
}
4863
}
4964

5065
private object Loader
Binary file not shown.

io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import java.util.zip.ZipEntry
99
import java.util.zip.ZipFile
1010
import java.util.zip.ZipInputStream
1111
import kotlin.io.path.exists
12+
import kotlin.io.path.inputStream
13+
import kotlin.io.path.name
1214
import okio.ByteString
1315
import okio.utf8Size
1416

@@ -94,8 +96,14 @@ private fun <T : Zip.Entry> ZipEntry.toZipEntry(
9496
internal fun Path.toZip(): Zip {
9597
val fs = asZipFileSystem()
9698
val root = fs.rootDirectories.single()!!
97-
val entries = ZipFile(toFile()).mapEntries { name, size, compressedSize, zipSize, isCompressed ->
98-
PathZip.Entry(root, name, size, compressedSize, zipSize, isCompressed)
99+
val entries = try {
100+
ZipFile(toFile()).mapEntries { name, size, compressedSize, zipSize, isCompressed ->
101+
PathZip.Entry(root, name, size, compressedSize, zipSize, isCompressed)
102+
}
103+
} catch (ex: UnsupportedOperationException) {
104+
inputStream().asZip().mapEntries { name, size, compressedSize, zipSize, isCompressed ->
105+
PathZip.Entry(root, name, size, compressedSize, zipSize, isCompressed)
106+
}
99107
}
100108
return PathZip(fs, entries)
101109
}

0 commit comments

Comments
 (0)