From a938ee1efb9c9a3f0291002bc3d90a1499704d97 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 4 Apr 2023 01:26:18 +0600 Subject: [PATCH] simplify API of MPPFile.input --- .../linuxX64Main/kotlin/ActualMPPFileInput.kt | 28 ++---------------- .../mingwX64Main/kotlin/ActualMPPFileInput.kt | 29 ++----------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/ktor/common/src/linuxX64Main/kotlin/ActualMPPFileInput.kt b/ktor/common/src/linuxX64Main/kotlin/ActualMPPFileInput.kt index 71d65288dfb..482635d4e6a 100644 --- a/ktor/common/src/linuxX64Main/kotlin/ActualMPPFileInput.kt +++ b/ktor/common/src/linuxX64Main/kotlin/ActualMPPFileInput.kt @@ -1,33 +1,11 @@ package dev.inmo.micro_utils.ktor.common import dev.inmo.micro_utils.common.MPPFile -import io.ktor.utils.io.bits.Memory -import io.ktor.utils.io.bits.loadByteArray +import dev.inmo.micro_utils.common.bytesAllocatorSync +import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.Input -import okio.FileSystem -import okio.Path - -private class FileInput( - private val path: Path -) : Input() { - private val openedFile = FileSystem.SYSTEM.openReadOnly(path) - override fun closeSource() { - openedFile.close() - } - - override fun fill(destination: Memory, offset: Int, length: Int): Int { - val byteArray = ByteArray(length) - val read = openedFile.read(offset.toLong(), byteArray, 0, length) - destination.loadByteArray( - offset, - byteArray, - count = length - ) - return read - } -} actual fun MPPFile.input(): Input { - return FileInput(this) + return ByteReadPacket(bytesAllocatorSync()) } diff --git a/ktor/common/src/mingwX64Main/kotlin/ActualMPPFileInput.kt b/ktor/common/src/mingwX64Main/kotlin/ActualMPPFileInput.kt index 71d65288dfb..31094804933 100644 --- a/ktor/common/src/mingwX64Main/kotlin/ActualMPPFileInput.kt +++ b/ktor/common/src/mingwX64Main/kotlin/ActualMPPFileInput.kt @@ -1,33 +1,10 @@ package dev.inmo.micro_utils.ktor.common import dev.inmo.micro_utils.common.MPPFile -import io.ktor.utils.io.bits.Memory -import io.ktor.utils.io.bits.loadByteArray +import dev.inmo.micro_utils.common.bytesAllocatorSync +import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.Input -import okio.FileSystem -import okio.Path - -private class FileInput( - private val path: Path -) : Input() { - private val openedFile = FileSystem.SYSTEM.openReadOnly(path) - override fun closeSource() { - openedFile.close() - } - - override fun fill(destination: Memory, offset: Int, length: Int): Int { - val byteArray = ByteArray(length) - val read = openedFile.read(offset.toLong(), byteArray, 0, length) - destination.loadByteArray( - offset, - byteArray, - count = length - ) - return read - } -} actual fun MPPFile.input(): Input { - return FileInput(this) + return ByteReadPacket(bytesAllocatorSync()) } -