SeekableSource

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
}

Inheritors

DirectSeekableSource
NodeFileSeekableSource

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract fun length(): Long

Returns the total size of the underlying data source in bytes.

Link copied to clipboard
abstract fun position(): Long

Returns the current zero-based read offset in bytes from the beginning of the stream.

Link copied to clipboard
abstract fun read(buffer: ByteArray, offset: Int, length: Int): Int

Reads up to length bytes from the current position into buffer starting at offset.

Link copied to clipboard
abstract fun seek(position: Long)

Sets the absolute byte offset from the beginning of the stream for the next read operation.