Skip to content

Commit 2b9f6d2

Browse files
committed
Replace Size with ByteSize
1 parent a36b7b5 commit 2b9f6d2

14 files changed

Lines changed: 105 additions & 125 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
**Added**
77
- Add `--summary-only` flag.
88

9+
**Changed**
10+
- Replace `com.jakewharton.diffuse.io.Size` with `me.saket.bytesize.ByteSize` in the APIs.
11+
912
**Fixed**
1013
- Significantly improve `.jar` diff performance.
1114

formats/api/formats.api

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ public final class com/jakewharton/diffuse/format/Apk$Companion {
9797
}
9898

9999
public final class com/jakewharton/diffuse/format/ArchiveFile {
100-
public synthetic fun <init> (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZLkotlin/jvm/internal/DefaultConstructorMarker;)V
100+
public fun <init> (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;Lme/saket/bytesize/ByteSize;Lme/saket/bytesize/ByteSize;Z)V
101101
public final fun component1 ()Ljava/lang/String;
102102
public final fun component2 ()Lcom/jakewharton/diffuse/format/ArchiveFile$Type;
103-
public final fun component3-kab5oJg ()J
104-
public final fun component4-kab5oJg ()J
103+
public final fun component3 ()Lme/saket/bytesize/ByteSize;
104+
public final fun component4 ()Lme/saket/bytesize/ByteSize;
105105
public final fun component5 ()Z
106-
public final fun copy-Ws8QFX4 (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZ)Lcom/jakewharton/diffuse/format/ArchiveFile;
107-
public static synthetic fun copy-Ws8QFX4$default (Lcom/jakewharton/diffuse/format/ArchiveFile;Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZILjava/lang/Object;)Lcom/jakewharton/diffuse/format/ArchiveFile;
106+
public final fun copy (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;Lme/saket/bytesize/ByteSize;Lme/saket/bytesize/ByteSize;Z)Lcom/jakewharton/diffuse/format/ArchiveFile;
107+
public static synthetic fun copy$default (Lcom/jakewharton/diffuse/format/ArchiveFile;Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;Lme/saket/bytesize/ByteSize;Lme/saket/bytesize/ByteSize;ZILjava/lang/Object;)Lcom/jakewharton/diffuse/format/ArchiveFile;
108108
public fun equals (Ljava/lang/Object;)Z
109109
public final fun getPath ()Ljava/lang/String;
110-
public final fun getSize-kab5oJg ()J
110+
public final fun getSize ()Lme/saket/bytesize/ByteSize;
111111
public final fun getType ()Lcom/jakewharton/diffuse/format/ArchiveFile$Type;
112-
public final fun getUncompressedSize-kab5oJg ()J
112+
public final fun getUncompressedSize ()Lme/saket/bytesize/ByteSize;
113113
public fun hashCode ()I
114114
public final fun isCompressed ()Z
115115
public fun toString ()Ljava/lang/String;

formats/src/main/kotlin/com/jakewharton/diffuse/format/ArchiveFile.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.jakewharton.diffuse.format
22

33
import com.jakewharton.diffuse.format.Arsc as ArscFormat
4-
import com.jakewharton.diffuse.io.Size
54
import java.util.Locale
5+
import me.saket.bytesize.ByteSize
66

77
data class ArchiveFile(
88
val path: String,
99
val type: Type,
10-
val size: Size,
11-
val uncompressedSize: Size,
10+
val size: ByteSize,
11+
val uncompressedSize: ByteSize,
1212
val isCompressed: Boolean,
1313
) {
1414
enum class Type {

formats/src/main/kotlin/com/jakewharton/diffuse/format/ArchiveFiles.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.jakewharton.diffuse.format
22

33
import com.jakewharton.diffuse.format.ArchiveFile.Type
44
import com.jakewharton.diffuse.format.ArchiveFile.Type.Other
5-
import com.jakewharton.diffuse.io.Size
65
import com.jakewharton.diffuse.io.Zip
6+
import me.saket.bytesize.binaryBytes
77

88
class ArchiveFiles internal constructor(private val files: Map<String, ArchiveFile>) :
99
Map<String, ArchiveFile> by files {
@@ -26,7 +26,7 @@ class ArchiveFiles internal constructor(private val files: Map<String, ArchiveFi
2626
it.isCompressed,
2727
)
2828
}
29-
.plus("/" to ArchiveFile("/", Other, Size(22), Size.ZERO, false))
29+
.plus("/" to ArchiveFile("/", Other, 22.binaryBytes, 0.binaryBytes, false))
3030
.let(::ArchiveFiles)
3131
}
3232
}

io/api/io.api

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,6 @@ public final class com/jakewharton/diffuse/io/PathInput : com/jakewharton/diffus
4444
public fun toZip ()Lcom/jakewharton/diffuse/io/Zip;
4545
}
4646

47-
public final class com/jakewharton/diffuse/io/Size : java/lang/Comparable {
48-
public static final field Companion Lcom/jakewharton/diffuse/io/Size$Companion;
49-
public static final synthetic fun box-impl (J)Lcom/jakewharton/diffuse/io/Size;
50-
public synthetic fun compareTo (Ljava/lang/Object;)I
51-
public fun compareTo-p-hSGm4 (J)I
52-
public static fun compareTo-p-hSGm4 (JJ)I
53-
public static fun constructor-impl (J)J
54-
public fun equals (Ljava/lang/Object;)Z
55-
public static fun equals-impl (JLjava/lang/Object;)Z
56-
public static final fun equals-impl0 (JJ)Z
57-
public static final fun getAbsoluteValue-kab5oJg (J)J
58-
public final fun getBytes ()J
59-
public fun hashCode ()I
60-
public static fun hashCode-impl (J)I
61-
public static final fun minus-2SwpbTA (JJ)J
62-
public static final fun plus-2SwpbTA (JJ)J
63-
public fun toString ()Ljava/lang/String;
64-
public static fun toString-impl (J)Ljava/lang/String;
65-
public static final fun unaryMinus-kab5oJg (J)J
66-
public final synthetic fun unbox-impl ()J
67-
}
68-
69-
public final class com/jakewharton/diffuse/io/Size$Companion {
70-
public final fun getZERO-kab5oJg ()J
71-
}
72-
7347
public final class com/jakewharton/diffuse/io/StringInput : com/jakewharton/diffuse/io/Input {
7448
public fun getName ()Ljava/lang/String;
7549
public fun source ()Lokio/Buffer;
@@ -95,10 +69,10 @@ public final class com/jakewharton/diffuse/io/Zip$DefaultImpls {
9569

9670
public abstract interface class com/jakewharton/diffuse/io/Zip$Entry {
9771
public abstract fun asInput ()Lcom/jakewharton/diffuse/io/Input;
98-
public abstract fun getCompressedSize-kab5oJg ()J
72+
public abstract fun getCompressedSize ()Lme/saket/bytesize/ByteSize;
9973
public abstract fun getPath ()Ljava/lang/String;
100-
public abstract fun getUncompressedSize-kab5oJg ()J
101-
public abstract fun getZipSize-kab5oJg ()J
74+
public abstract fun getUncompressedSize ()Lme/saket/bytesize/ByteSize;
75+
public abstract fun getZipSize ()Lme/saket/bytesize/ByteSize;
10276
public abstract fun isCompressed ()Z
10377
}
10478

io/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'org.jetbrains.dokka'
44

55
dependencies {
66
api libs.okio
7-
implementation libs.bytesize
7+
api libs.bytesize
88

99
testImplementation libs.junit
1010
testImplementation libs.assertk

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

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import java.util.zip.ZipEntry
99
import java.util.zip.ZipInputStream
1010
import kotlin.io.path.exists
1111
import kotlin.io.path.inputStream
12+
import me.saket.bytesize.BinaryByteSize
13+
import me.saket.bytesize.ByteSize
1214
import okio.ByteString
1315
import okio.utf8Size
1416

@@ -47,13 +49,13 @@ interface Zip : Closeable {
4749
val path: String
4850

4951
/** The uncompressed size of the entry contents */
50-
val uncompressedSize: Size
52+
val uncompressedSize: ByteSize
5153

5254
/** The compressed size of the entry contents. */
53-
val compressedSize: Size
55+
val compressedSize: ByteSize
5456

5557
/** The impact on the overall zip size. This is [compressedSize] plus metadata. */
56-
val zipSize: Size
58+
val zipSize: ByteSize
5759

5860
/** Returns true if the entry is compressed using any method other than 'store'. */
5961
val isCompressed: Boolean
@@ -64,15 +66,27 @@ interface Zip : Closeable {
6466

6567
private fun <T : Zip.Entry> ZipInputStream.mapEntries(
6668
entryFactory:
67-
(name: String, size: Size, compressedSize: Size, zipSize: Size, isCompressed: Boolean) -> T
69+
(
70+
name: String,
71+
size: ByteSize,
72+
compressedSize: ByteSize,
73+
zipSize: ByteSize,
74+
isCompressed: Boolean,
75+
) -> T
6876
): List<T> {
6977
return entries().map { it.toZipEntry(this, entryFactory) }.toList()
7078
}
7179

7280
private fun <T : Zip.Entry> ZipEntry.toZipEntry(
7381
zipStream: ZipInputStream,
7482
entryFactory:
75-
(name: String, size: Size, compressedSize: Size, zipSize: Size, isCompressed: Boolean) -> T,
83+
(
84+
name: String,
85+
size: ByteSize,
86+
compressedSize: ByteSize,
87+
zipSize: ByteSize,
88+
isCompressed: Boolean,
89+
) -> T,
7690
): T {
7791
val isCompressed = method != ZipEntry.STORED
7892
val nameSize = name.utf8Size()
@@ -113,7 +127,13 @@ private fun <T : Zip.Entry> ZipEntry.toZipEntry(
113127
extraSize +
114128
commentSize
115129

116-
return entryFactory(name, Size(size), Size(compressedSize), Size(zipSize), isCompressed)
130+
return entryFactory(
131+
name,
132+
BinaryByteSize(size),
133+
BinaryByteSize(compressedSize),
134+
BinaryByteSize(zipSize),
135+
isCompressed,
136+
)
117137
}
118138

119139
internal fun Path.toZip(): Zip {
@@ -133,9 +153,9 @@ internal class PathZip(fs: FileSystem, override val entries: List<Zip.Entry>) :
133153
class Entry(
134154
private val root: Path,
135155
override val path: String,
136-
override val uncompressedSize: Size,
137-
override val compressedSize: Size,
138-
override val zipSize: Size,
156+
override val uncompressedSize: ByteSize,
157+
override val compressedSize: ByteSize,
158+
override val zipSize: ByteSize,
139159
override val isCompressed: Boolean,
140160
) : Zip.Entry {
141161
override fun asInput(): Input {
@@ -160,9 +180,9 @@ internal class BytesZip(override val entries: List<Zip.Entry>) : Zip {
160180
class Entry(
161181
private val bytes: ByteString,
162182
override val path: String,
163-
override val uncompressedSize: Size,
164-
override val compressedSize: Size,
165-
override val zipSize: Size,
183+
override val uncompressedSize: ByteSize,
184+
override val compressedSize: ByteSize,
185+
override val zipSize: ByteSize,
166186
override val isCompressed: Boolean,
167187
) : Zip.Entry {
168188
override fun asInput(): Input {

io/src/test/kotlin/com/jakewharton/diffuse/io/SizeTest.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

io/src/test/kotlin/com/jakewharton/diffuse/io/ZipTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.jakewharton.diffuse.io
33
import assertk.assertThat
44
import assertk.assertions.isEqualTo
55
import com.jakewharton.diffuse.testing.decodeHexWithWhitespace
6+
import me.saket.bytesize.binaryBytes
67
import org.junit.Test
78

89
class ZipTest {
@@ -23,7 +24,7 @@ class ZipTest {
2324
.toZip()
2425
val entry = zip.entries.single()
2526

26-
assertThat(entry.compressedSize).isEqualTo(Size(7))
27-
assertThat(entry.uncompressedSize).isEqualTo(Size(5))
27+
assertThat(entry.compressedSize).isEqualTo(7.binaryBytes)
28+
assertThat(entry.uncompressedSize).isEqualTo(5.binaryBytes)
2829
}
2930
}

0 commit comments

Comments
 (0)