fixed FileBinary

This commit is contained in:
Alexander Nozik 2019-05-28 18:56:22 +03:00
parent 65a5379f4a
commit cffb02d483

View File

@ -3,13 +3,19 @@ package hep.dataforge.io
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.Input
import java.nio.channels.FileChannel
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardOpenOption
class FileBinary(val path: Path, private val offset: Int = 0) : RandomAccessBinary {
override fun <R> read(from: Long, size: Long, block: Input.() -> R): R {
override val size: ULong
get() = (Files.size(path) - offset).toULong()
override fun <R> read(from: UInt, size: UInt, block: Input.() -> R): R {
FileChannel.open(path, StandardOpenOption.READ).use {
val buffer = it.map(FileChannel.MapMode.READ_ONLY, from + offset, size)
val buffer = it.map(FileChannel.MapMode.READ_ONLY, (from.toLong() + offset), size.toLong())
return ByteReadPacket(buffer).block()
}
}