Skip to content

Commit

Permalink
Merge pull request #104 from d-r-q/q103/mpp/byte-array-to-input
Browse files Browse the repository at this point in the history
Replace frozen kotlin io 0.16 by ktor version to implement ByteArray.asInput(): Input
  • Loading branch information
Aleksey authored May 27, 2020
2 parents 41e2ce5 + 838c963 commit cd134b0
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 47 deletions.
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ kotlin.code.style=official
kotlin_version=1.4-M1
systemProp.kotlin_version=1.4-M1
kotlin_serialization_version=0.20.0-1.4-M1
kotlin_io_version=0.1.16
ktor_version=1.3.2-1.4-M1
2 changes: 0 additions & 2 deletions qbit-core-jvm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ kotlin {
api kotlin("reflect")
api project(":qbit-core")
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialization_version"
api "org.jetbrains.kotlinx:kotlinx-io:$kotlin_io_version"
}
}
commonTest {
Expand All @@ -31,7 +30,6 @@ kotlin {
jvmMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
api "org.jetbrains.kotlinx:kotlinx-io-jvm:$kotlin_io_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialization_version"
}
}
Expand Down
5 changes: 0 additions & 5 deletions qbit-core-jvm/src/commonMain/kotlin/qbit/platform/Io.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package qbit.serialization

import kotlinx.io.core.Input
import io.ktor.utils.io.core.Input
import qbit.api.model.Hash
import qbit.api.system.DbUuid

Expand Down
12 changes: 4 additions & 8 deletions qbit-core-jvm/src/commonMain/kotlin/qbit/serialization/Simple.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package qbit.serialization

import kotlinx.io.charsets.Charset
import kotlinx.io.charsets.decode
import kotlinx.io.charsets.encode
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.EOFException
import kotlinx.io.core.ExperimentalIoApi
import kotlinx.io.core.Input
import kotlinx.io.core.readAvailable
import io.ktor.utils.io.charsets.Charset
import io.ktor.utils.io.charsets.decode
import io.ktor.utils.io.charsets.encode
import io.ktor.utils.io.core.*
import qbit.api.gid.Gid
import qbit.api.gid.Iid
import qbit.api.model.DataType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package qbit

import kotlinx.io.core.EOFException
import kotlinx.io.core.ExperimentalIoApi
import kotlinx.io.core.Input
import io.ktor.utils.io.core.EOFException
import io.ktor.utils.io.core.ExperimentalIoApi
import io.ktor.utils.io.core.Input
import qbit.api.gid.Gid
import qbit.api.gid.Iid
import qbit.api.model.*
Expand Down
9 changes: 0 additions & 9 deletions qbit-core-jvm/src/jvmMain/kotlin/qbit/platform/Io.kt

This file was deleted.

7 changes: 5 additions & 2 deletions qbit-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val kotlin_serialization_version: String by rootProject.extra
val kotlin_io_version: String by rootProject.extra
val ktor_version: String by rootProject.extra

kotlin {

Expand All @@ -18,6 +18,7 @@ kotlin {
dependencies {
api(kotlin("stdlib-common"))
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialization_version")
api("io.ktor:ktor-io:$ktor_version")
}
}
val commonTest by getting {
Expand All @@ -30,8 +31,8 @@ kotlin {
val jvmMain by getting {
dependencies {
api(kotlin("stdlib-jdk8"))
api("org.jetbrains.kotlinx:kotlinx-io-jvm:$kotlin_io_version")
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialization_version")
api("io.ktor:ktor-io-jvm:$ktor_version")
}
}
val jvmTest by getting {
Expand All @@ -43,6 +44,7 @@ kotlin {
dependencies {
api(kotlin("stdlib"))
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$kotlin_serialization_version")
api("io.ktor:ktor-io-native:$ktor_version")
}
}
val linuxTest by getting {
Expand All @@ -53,6 +55,7 @@ kotlin {
dependencies {
api(kotlin("stdlib-js"))
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialization_version")
api("io.ktor:ktor-io-js:$ktor_version")
}
}
val nodeJsTest by getting {
Expand Down
8 changes: 8 additions & 0 deletions qbit-core/src/commonMain/kotlin/qbit/platform/Io.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package qbit.platform

import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input

fun ByteArray.asInput(): Input {
return ByteReadPacket(this, 0, this.size)
}
1 change: 1 addition & 0 deletions qbit-fss/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kotlin {
commonMain {
dependencies {
api project(':qbit-core-jvm')
api 'io.ktor:ktor-io:$ktor_version'
}
}
commonTest {
Expand Down
8 changes: 5 additions & 3 deletions qbit-fss/src/commonMain/kotlin/qbit/platform/File.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package qbit.platform

import kotlinx.io.core.Output
import io.ktor.utils.io.core.Output

expect class File {
constructor(parent: File, child: String)
Expand Down Expand Up @@ -29,11 +29,13 @@ expect class FileDescriptor {
fun sync()
}

expect fun fileOutput(file: File): FileOutput
expect fun fileOutput(file: File): QOutput

interface FileOutput : Output {
interface QOutput : Output {

val fd: FileDescriptor

fun writeFully(data: ByteArray)

}

11 changes: 3 additions & 8 deletions qbit-fss/src/commonMain/kotlin/qbit/storage/FileSystemStorage.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package qbit.storage

import kotlinx.io.core.use
import kotlinx.io.core.writeFully
import kotlinx.io.errors.IOException
import io.ktor.utils.io.core.use
import io.ktor.utils.io.errors.IOException
import qbit.api.QBitException
import qbit.ns.Key
import qbit.ns.Namespace
import qbit.platform.File
import qbit.platform.fileOutput
import qbit.platform.listFiles
import qbit.platform.readBytes
import qbit.platform.resolve
import qbit.platform.*
import qbit.spi.Storage

class FileSystemStorage(private val root: File) : Storage {
Expand Down
16 changes: 11 additions & 5 deletions qbit-fss/src/jvmMain/kotlin/qbit/platform/File.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package qbit.platform

import kotlinx.io.core.Output
import kotlinx.io.streams.asOutput
import io.ktor.utils.io.core.Output
import io.ktor.utils.io.streams.asOutput
import java.io.FileOutputStream
import java.nio.file.Files
import kotlin.io.readBytes as readBytesImpl
Expand Down Expand Up @@ -33,9 +33,15 @@ actual object Files {
actual fun createTempDirectory(prefix: String): Path = Files.createTempDirectory(prefix)
}

actual fun fileOutput(file: File): FileOutput {
actual fun fileOutput(file: File): QOutput {
val fos = FileOutputStream(file)
return FileOutputImpl(fos.asOutput(), fos.fd)
return FileOutputImpl(fos, fos.asOutput(), fos.fd)
}

class FileOutputImpl(out: Output, override val fd: FileDescriptor) : FileOutput, Output by out
class FileOutputImpl(val fos: FileOutputStream, out: Output, override val fd: FileDescriptor) : QOutput, Output by out {

override fun writeFully(data: ByteArray) {
fos.write(data)
}

}

0 comments on commit cd134b0

Please sign in to comment.