ZipReader

class 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, multi-disk archives, and archives above 2 GB (the whole file is held in one ByteArray).

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.

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 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.