From 9893279b03658b08c750de71a6cff0725006786a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 2 Apr 2026 17:48:31 -0400 Subject: [PATCH] Compute image hashes without having to load the entire file in memory --- .../amethyst/ui/components/ZoomableContentView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt index 357f85ec4..6321e4fd4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt @@ -109,7 +109,7 @@ import com.vitorpamplona.quartz.nip19Bech32.Nip19Parser import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent import com.vitorpamplona.quartz.nip94FileMetadata.tags.DimensionTag import com.vitorpamplona.quartz.utils.Log -import com.vitorpamplona.quartz.utils.sha256.sha256 +import com.vitorpamplona.quartz.utils.sha256.sha256StreamWithCount import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.CancellationException @@ -1035,8 +1035,8 @@ private fun verifyHash(content: MediaUrlContent): Boolean? { if (content.hash == null) return null Amethyst.instance.diskCache.openSnapshot(content.url)?.use { snapshot -> - val hash = sha256(snapshot.data.toFile().readBytes()).toHexKey() - return hash == content.hash + val (hashBytes, _) = sha256StreamWithCount(snapshot.data.toFile().inputStream()) + return hashBytes.toHexKey() == content.hash } return null