Seekable Source
A random-access byte stream from which KioArch reads archive headers and compressed payloads.
Implementations provide synchronous read and seek operations over an underlying storage medium such as an in-memory ByteArray (ByteArraySeekableSource), a local file, an Android ParcelFileDescriptor, or a remote network/SMB stream.
When passed to KioArch.createReader, the SeekableSource is closed automatically when the resulting ArchiveReader is closed.
Custom Implementation Example
class CustomSeekableSource(private val data: ByteArray) : SeekableSource {
private var offset = 0L
override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
if (this.offset >= data.size) return -1
val count = minOf(length.toLong(), data.size - this.offset).toInt()
data.copyInto(buffer, offset, this.offset.toInt(), this.offset.toInt() + count)
this.offset += count
return count
}
override fun seek(position: Long) {
this.offset = position.coerceIn(0L, data.size.toLong())
}
override fun position(): Long = offset
override fun length(): Long = data.size.toLong()
override fun close() = Unit
}Content copied to clipboard