From cffb02d483af8ab67e6a564256fe792eb33fa964 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 28 May 2019 18:56:22 +0300 Subject: [PATCH] fixed FileBinary --- .../src/jvmMain/kotlin/hep/dataforge/io/FileBinary.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/FileBinary.kt b/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/FileBinary.kt index 3154a2cf..db74e8e0 100644 --- a/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/FileBinary.kt +++ b/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/FileBinary.kt @@ -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 read(from: Long, size: Long, block: Input.() -> R): R { + + override val size: ULong + get() = (Files.size(path) - offset).toULong() + + + override fun 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() } }