Technical Architecture: In-Browser EPUB to MOBI Binary Synthesis
The transition from reflowable EPUB (Electronic Publication) packages to the legacy Mobipocket (MOBI) binary format requires bridging two fundamentally divergent eBook paradigms. While EPUB is an open container housing distinct XHTML files and CSS stylesheets inside a ZIP archive, MOBI is an adaptation of the historic PalmOS Palm Database (PDB/PRC) structure.
In a MOBI file, text content is compiled into sequential records of 4,096 bytes each, preceded by a master Palm Database header and indexed by a record offset table. 2ClickKit provides a 100% client-side pipeline that reads EPUB archives, traverses the narrative spine, synthesizes Kindle-compliant HTML, and assembles the low-level byte stream required for native Kindle hardware playback.
Anatomy of the Mobipocket Palm Database (PRC/MOBI)
To understand how 2ClickKit constructs valid MOBI files in JavaScript without external native binaries, review the underlying byte structure:
| Component / Offset | Length | Description & Specification Requirements |
|---|---|---|
| Palm Database Name | 32 Bytes | ASCII string identifying the database, null-padded at byte boundary. |
| Header Attributes & Version | 4 Bytes | Bitmask flags and schema version (uint16 big-endian). |
| Creation & Mod Timestamps | 8 Bytes | Seconds elapsed since the Palm epoch: January 1, 1904 (UTC). |
| Type & Creator IDs | 8 Bytes | FourCC signatures: Type = 'BOOK', Creator = 'MOBI'. |
| Record Count & Table | Variable | uint16 record count followed by 8-byte entries: 4-byte offset, 1-byte attribute, 3-byte unique ID. |
| Record 0 (MOBI Header) | Variable | Contains PalmDOC compression flags, uncompressed text length, MOBI identifier, and EXTH tags. |
| Records 1 to N (Text) | <= 4,096 Bytes | Contiguous slices of UTF-8 encoded HTML text with Kindle pagination tags. |
| Trailing Records | Variable | Includes FLIS (feature index), FCIS, and 2-byte end-of-file markers (0xE9 0x8E). |
PalmDOC Compression vs Uncompressed Record Storage
The PalmDOC standard supports two primary text storage modes:
- Compression Type 1 (Uncompressed): The HTML document is partitioned into 4,096-byte slices and stored directly as raw UTF-8 bytes. This mode guarantees universal readability across every version of Amazon Kindle firmware, Calibre, and mobile e-readers with zero CPU overhead.
- Compression Type 2 (PalmDOC LZ77): A sliding-window byte compression algorithm where literal bytes, space-character run pairs (
0xC0-0xFF), and backward distance/length pointers (0x80-0xBF) compress repetitive words.
2ClickKit utilizes high-speed uncompressed Type 1 chunking with full EXTH metadata tagging, maximizing hardware battery efficiency and rendering fidelity on e-ink Kindle displays.
Extended Header (EXTH) Metadata Integration
In addition to the legacy PalmDOC record, modern Kindle readers rely on the EXTH Header positioned immediately after the MOBI header block in Record 0. This metadata block informs the Kindle operating system of author information, cover art references, and publishing provenance:
- Tag 100: Author / Creator string (displayed in Kindle Home Library).
- Tag 101: Publisher information.
- Tag 503: Updated Book Title string in full UTF-8.
- Tag 106: Publication date formatted as ISO-8601.
Comparison: 2ClickKit vs Calibre vs Cloud Conversion Platforms
| Conversion Dimension | 2ClickKit (In-Browser) | Calibre (Desktop Suite) | CloudConvert |
|---|---|---|---|
| Execution Environment | Client RAM (V8 / JavaScriptCore) | Local Python native runtime | Remote Cloud Server |
| File Privacy & Confidentiality | 100% Private (No uploads) | 100% Private (Local machine) | Uploaded to third-party server |
| Setup / Install Required | Zero Install | ~150MB+ installation | Account / API Key |
| Execution Speed | < 1.5 seconds | 3 - 8 seconds | 15 - 45 seconds (queue + transfer) |
| Device Portability | Desktop, Chromebook, iOS, Android | Desktop OS only | Browser dependent |
Developer Implementation: Building MOBI in TypeScript
Below is an illustrative snippet showing how 2ClickKit packs Palm database records into binary arrays:
// Client-side TypeScript snippet for Palm Database record packing
function compilePalmDatabase(title: string, records: Uint8Array[]): Uint8Array {
const numRecords = records.length;
const headerSize = 78 + (numRecords * 8) + 2;
let totalSize = headerSize;
const offsets: number[] = [];
for (const rec of records) {
offsets.push(totalSize);
totalSize += rec.length;
}
const buffer = new Uint8Array(totalSize);
const view = new DataView(buffer.buffer);
// Write FourCC 'BOOK' and 'MOBI'
const encoder = new TextEncoder();
buffer.set(encoder.encode(title.substring(0, 31)), 0);
buffer.set(encoder.encode('BOOK'), 60);
buffer.set(encoder.encode('MOBI'), 64);
view.setUint16(76, numRecords, false);
// Write record offset table
for (let i = 0; i < numRecords; i++) {
view.setUint32(78 + (i * 8), offsets[i], false);
buffer[78 + (i * 8) + 4] = 0; // attributes
}
// Copy records
for (let i = 0; i < numRecords; i++) {
buffer.set(records[i], offsets[i]);
}
return buffer;
} Tips for Kindle Side-Loading
- USB Transfer: Connect your Kindle to your computer using a standard USB cable. Locate the Kindle drive in File Explorer or Finder and copy your
.mobifile into thedocumentsdirectory. - E-Ink Refresh: Once copied, safely eject your Kindle. The new book will appear in your library with author name and full pagination.