ZipReader

ZIP reader for EPUB / OCF / CBZ containers. Parses the central directory, then reads entries on demand (STORED or raw DEFLATE via the shared inflater).

What it handles: methods 0 and 8, ZIP64 records (both the end-of-central- directory pair and the per-entry extra field), entries whose sizes live in a trailing data descriptor, and CRC-32 verification.

What it does not: encryption, and multi-disk archives. A reader built on a ByteArray also stops at 2 GB; one built on a KiteByteSource holds only the central directory and the entry it is reading, so the archive can be larger than the heap.

CRC mismatches are lenient by default: read hands the bytes back and logs, because half a broken book beats no book. Pass strictCrc to get null instead, or call verify to ask without reading. maxEntryBytes and maxEntries bound decompression and central-directory resource use.

Constructors

Link copied to clipboard
constructor(bytes: ByteArray, strictCrc: Boolean = false)

Open bytes with default resource ceilings.

constructor(bytes: ByteArray, strictCrc: Boolean = false, maxEntryBytes: Int = DEFAULT_MAX_ENTRY_BYTES, maxEntries: Int = DEFAULT_MAX_ENTRIES)

Open bytes with explicit decompressed-entry and record-count ceilings.

constructor(source: KiteByteSource, strictCrc: Boolean = false, maxEntryBytes: Int = DEFAULT_MAX_ENTRY_BYTES, maxEntries: Int = DEFAULT_MAX_ENTRIES)

Open the archive in source, reading entries from it as they are asked for. The caller keeps source open while this reader lives. A failed read of the source makes the entry unreadable, or the archive empty when it hits the central directory, as a damaged archive would.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Entry names, in central-directory order.

Functions

Link copied to clipboard

Header facts about name, or null if absent.

Link copied to clipboard
fun read(name: String): ByteArray?

Decompressed bytes of name, or null if absent / unreadable.

Link copied to clipboard
fun readPrefix(name: String, maxBytes: Int): ByteArray?

The first maxBytes bytes of name, or all of them when the entry is shorter, or null when it is absent or unreadable. It inflates only as far as it needs and checks no CRC-32, so it reads a file's header without the rest of it.

Link copied to clipboard
fun readText(name: String, encodingHint: String? = null): String?

Text of name, or null. The encoding is sniffed rather than assumed: see TextEncoding. Pass encodingHint when something outside the file knows better, e.g. an HTTP Content-Type.

Link copied to clipboard
fun verify(name: String): Boolean?

True when name's bytes match the CRC-32 the archive claims, false when they do not, null when the entry is absent, unreadable, or carries no CRC to check against.