diff --git a/README.md b/README.md index 84050324..8dd5d1d4 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ of Ashampoo Photos, which, in turn, is driven by user community feedback. ## Installation ``` -implementation("com.ashampoo:kim:0.16.1") +implementation("com.ashampoo:kim:0.16.2") ``` For the targets `wasmJs` & `js` you also need to specify this: @@ -52,9 +52,9 @@ implementation(npm("pako", "2.1.0")) ### Read metadata -`Kim.readMetadata()` takes `kotlin.ByteArray`, `kotlinx.io.files.Path`, Ktor `ByteReadPacket` & -Ktor `ByteReadChannel` on all platforms and depending on the platform also `java.io.File`, -`java.io.InputStream`, `NSData` and string paths. +`Kim.readMetadata()` takes `kotlin.ByteArray` on all platforms and depending on +the platform also `kotlinx.io.files.Path`, Ktor `ByteReadPacket` & `ByteReadChannel`, +`java.io.File`, `java.io.InputStream`, `NSData` and `String` paths. ```kotlin val bytes: ByteArray = loadBytes() diff --git a/build.gradle.kts b/build.gradle.kts index 115dd266..586ddaf1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -168,7 +168,7 @@ kotlin { } } - js() { + js { // nodejs() } @@ -193,9 +193,6 @@ kotlin { /* XMP handling */ api("com.ashampoo:xmpcore:$xmpCoreVersion") - - /* Multiplatform file access */ - api("org.jetbrains.kotlinx:kotlinx-io-core:$ioCoreVersion") } } @@ -236,13 +233,28 @@ kotlin { } } + /* + * Extra sourceSet to exclude unsupported features from JS / wasmJS targets. + */ val ktorMain by sourceSets.creating { dependsOn(commonMain) dependencies { + /* + * Ktor extensions + * + * Not available in commonMain due to missing WASM support. + */ api("io.ktor:ktor-io:$ktorVersion") + + /* + * Multiplatform file access + * + * Not available in commonMain due to missing JS browser support. + */ + api("org.jetbrains.kotlinx:kotlinx-io-core:$ioCoreVersion") } } @@ -281,6 +293,7 @@ kotlin { dependsOn(posixMain) } + val iosArm64Main by sourceSets.getting val iosX64Main by sourceSets.getting val iosSimulatorArm64Main by sourceSets.getting diff --git a/src/commonMain/kotlin/com/ashampoo/kim/Kim.kt b/src/commonMain/kotlin/com/ashampoo/kim/Kim.kt index 1c480a51..db927c38 100644 --- a/src/commonMain/kotlin/com/ashampoo/kim/Kim.kt +++ b/src/commonMain/kotlin/com/ashampoo/kim/Kim.kt @@ -38,14 +38,12 @@ import com.ashampoo.kim.format.webp.WebPUpdater import com.ashampoo.kim.input.ByteArrayByteReader import com.ashampoo.kim.input.ByteReader import com.ashampoo.kim.input.DefaultRandomAccessByteReader -import com.ashampoo.kim.input.KotlinIoSourceByteReader import com.ashampoo.kim.input.PrePendingByteReader import com.ashampoo.kim.input.use import com.ashampoo.kim.model.ImageFormat import com.ashampoo.kim.model.MetadataUpdate import com.ashampoo.kim.output.ByteArrayByteWriter import com.ashampoo.kim.output.ByteWriter -import kotlinx.io.files.Path object Kim { @@ -59,16 +57,6 @@ object Kim { else readMetadata(ByteArrayByteReader(bytes)) - @OptIn(ExperimentalStdlibApi::class) - @kotlin.jvm.JvmStatic - @Throws(ImageReadException::class) - fun readMetadata(path: Path): ImageMetadata? = tryWithImageReadException { - - KotlinIoSourceByteReader.read(path) { byteReader -> - byteReader?.let { readMetadata(it) } - } - } - @kotlin.jvm.JvmStatic @Throws(ImageReadException::class) fun readMetadata( diff --git a/src/jvmTest/kotlin/com/ashampoo/kim/input/KotlinIoPathSourceTest.kt b/src/jvmTest/kotlin/com/ashampoo/kim/input/KotlinIoPathSourceTest.kt index 4bcc2e0c..2756814e 100644 --- a/src/jvmTest/kotlin/com/ashampoo/kim/input/KotlinIoPathSourceTest.kt +++ b/src/jvmTest/kotlin/com/ashampoo/kim/input/KotlinIoPathSourceTest.kt @@ -16,6 +16,7 @@ package com.ashampoo.kim.input import com.ashampoo.kim.Kim +import com.ashampoo.kim.readMetadata import com.ashampoo.kim.testdata.KimTestData import kotlinx.io.files.Path import kotlin.test.Test diff --git a/src/ktorMain/kotlin/com/ashampoo/kim/JvmKimExtensions.ktor.kt b/src/ktorMain/kotlin/com/ashampoo/kim/KtorKimExtensions.kt similarity index 76% rename from src/ktorMain/kotlin/com/ashampoo/kim/JvmKimExtensions.ktor.kt rename to src/ktorMain/kotlin/com/ashampoo/kim/KtorKimExtensions.kt index 608c36cc..7ccc7fab 100644 --- a/src/ktorMain/kotlin/com/ashampoo/kim/JvmKimExtensions.ktor.kt +++ b/src/ktorMain/kotlin/com/ashampoo/kim/KtorKimExtensions.kt @@ -16,11 +16,14 @@ package com.ashampoo.kim import com.ashampoo.kim.common.ImageReadException +import com.ashampoo.kim.common.tryWithImageReadException import com.ashampoo.kim.format.ImageMetadata +import com.ashampoo.kim.input.KotlinIoSourceByteReader import com.ashampoo.kim.input.KtorByteReadChannelByteReader import com.ashampoo.kim.input.KtorInputByteReader import io.ktor.utils.io.ByteReadChannel import io.ktor.utils.io.core.ByteReadPacket +import kotlinx.io.files.Path @Throws(ImageReadException::class) fun Kim.readMetadata(byteReadPacket: ByteReadPacket): ImageMetadata? = @@ -29,3 +32,12 @@ fun Kim.readMetadata(byteReadPacket: ByteReadPacket): ImageMetadata? = @Throws(ImageReadException::class) fun Kim.readMetadata(byteReadChannel: ByteReadChannel, contentLength: Long): ImageMetadata? = Kim.readMetadata(KtorByteReadChannelByteReader(byteReadChannel, contentLength)) + +@OptIn(ExperimentalStdlibApi::class) +@Throws(ImageReadException::class) +fun Kim.readMetadata(path: Path): ImageMetadata? = tryWithImageReadException { + + KotlinIoSourceByteReader.read(path) { byteReader -> + byteReader?.let { Kim.readMetadata(it) } + } +} diff --git a/src/commonMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt b/src/ktorMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt similarity index 100% rename from src/commonMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt rename to src/ktorMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt diff --git a/src/commonMain/kotlin/com/ashampoo/kim/format/png/PngMetadataCopyUtil.kt b/src/ktorMain/kotlin/com/ashampoo/kim/format/png/PngMetadataCopyUtil.kt similarity index 100% rename from src/commonMain/kotlin/com/ashampoo/kim/format/png/PngMetadataCopyUtil.kt rename to src/ktorMain/kotlin/com/ashampoo/kim/format/png/PngMetadataCopyUtil.kt diff --git a/src/commonMain/kotlin/com/ashampoo/kim/input/KotlinIoSourceByteReader.kt b/src/ktorMain/kotlin/com/ashampoo/kim/input/KotlinIoSourceByteReader.kt similarity index 100% rename from src/commonMain/kotlin/com/ashampoo/kim/input/KotlinIoSourceByteReader.kt rename to src/ktorMain/kotlin/com/ashampoo/kim/input/KotlinIoSourceByteReader.kt diff --git a/src/commonMain/kotlin/com/ashampoo/kim/output/KotlinIoSinkByteWriter.kt b/src/ktorMain/kotlin/com/ashampoo/kim/output/KotlinIoSinkByteWriter.kt similarity index 100% rename from src/commonMain/kotlin/com/ashampoo/kim/output/KotlinIoSinkByteWriter.kt rename to src/ktorMain/kotlin/com/ashampoo/kim/output/KotlinIoSinkByteWriter.kt