Skip to content

Commit

Permalink
Moved kotlinx-io out of commonMain (#80)
Browse files Browse the repository at this point in the history
The kotlinx-io dependency is moved out of commonMain, because the JS
target does not support it.
  • Loading branch information
StefanOltmann authored Mar 19, 2024
1 parent 3b9cd28 commit 991cd4c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
21 changes: 17 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ kotlin {
}
}

js() {
js {
// nodejs()
}

Expand All @@ -193,9 +193,6 @@ kotlin {

/* XMP handling */
api("com.ashampoo:xmpcore:$xmpCoreVersion")

/* Multiplatform file access */
api("org.jetbrains.kotlinx:kotlinx-io-core:$ioCoreVersion")
}
}

Expand Down Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -281,6 +293,7 @@ kotlin {
dependsOn(posixMain)
}


val iosArm64Main by sourceSets.getting
val iosX64Main by sourceSets.getting
val iosSimulatorArm64Main by sourceSets.getting
Expand Down
12 changes: 0 additions & 12 deletions src/commonMain/kotlin/com/ashampoo/kim/Kim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? =
Expand All @@ -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) }
}
}

0 comments on commit 991cd4c

Please sign in to comment.