mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 22:03:50 +00:00
simplify API of MPPFile.input
This commit is contained in:
parent
6ea5e2e5a6
commit
a938ee1efb
@ -1,33 +1,11 @@
|
|||||||
package dev.inmo.micro_utils.ktor.common
|
package dev.inmo.micro_utils.ktor.common
|
||||||
|
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
import io.ktor.utils.io.bits.Memory
|
import dev.inmo.micro_utils.common.bytesAllocatorSync
|
||||||
import io.ktor.utils.io.bits.loadByteArray
|
import io.ktor.utils.io.core.ByteReadPacket
|
||||||
import io.ktor.utils.io.core.Input
|
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 {
|
actual fun MPPFile.input(): Input {
|
||||||
return FileInput(this)
|
return ByteReadPacket(bytesAllocatorSync())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,33 +1,10 @@
|
|||||||
package dev.inmo.micro_utils.ktor.common
|
package dev.inmo.micro_utils.ktor.common
|
||||||
|
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
import io.ktor.utils.io.bits.Memory
|
import dev.inmo.micro_utils.common.bytesAllocatorSync
|
||||||
import io.ktor.utils.io.bits.loadByteArray
|
import io.ktor.utils.io.core.ByteReadPacket
|
||||||
import io.ktor.utils.io.core.Input
|
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 {
|
actual fun MPPFile.input(): Input {
|
||||||
return FileInput(this)
|
return ByteReadPacket(bytesAllocatorSync())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user