ArchiveReader

Reads metadata and extracts entries on demand from an open archive.

An ArchiveReader holds native decoder state and an underlying SeekableSource. Always close the reader when finished—typically via .use { ... }—to release native memory and close the underlying SeekableSource.

Thread Safety and Re-entrancy

Implementations synchronize access to the underlying native handle so concurrent calls across threads are serialized safely. However, invoking ArchiveReader methods re-entrantly from within a SeekableSource or Sink callback during an active operation is prohibited and throws IllegalStateException.

Usage Example

KioArch.createReader(archiveBytes).use { reader ->
val target = reader.getEntries().first { !it.isDirectory && it.name.endsWith(".txt") }
val buffer = kotlinx.io.Buffer()
reader.extractEntry(target, buffer)
println(buffer.readString())
}

See also

Inheritors

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
@ObjCName(name = "extractEntry", swiftName = "extract")
abstract fun extractEntry(entry: ArchiveEntry, sink: Sink)

Decompresses the specified entry and streams its raw content into sink.

Link copied to clipboard
abstract fun getEntries(): List<ArchiveEntry>

Returns all file and directory entries recorded in the archive.