Skip to main content

Overview

This function downloads the book’s database files, applies patches if available, creates the necessary database tables, and exports the data to the specified format. The output can be either a JSON file or a SQLite database file.

Function Signature

Parameters

number
required
The unique identifier of the book to download
DownloadBookOptions
required
Configuration options for downloading the book

Returns

string
The path of the created output file

Examples

Download as JSON

Download as SQLite Database

Using Pre-fetched Metadata

Download Multiple Books

Custom Writer for Browser

Output Format

SQLite Format

The SQLite database contains the following tables:
  • pages - Book pages with content
  • titles - Chapter/section titles with hierarchy

JSON Format

Patch Handling

The function automatically handles applying patches:
  • If a minor release (patch) is available, it’s downloaded and applied
  • Patches contain corrections and additions to the major release
  • The final output includes all patched data

Error Handling

This function throws an error when:
  • Download fails
  • Book database file is not found in the archive
  • Database operations fail
  • File write operations fail
  • Unsupported file extension is provided

Performance Considerations

  • Book sizes vary from a few MB to over 100MB
  • JSON format is typically larger than SQLite
  • Pre-fetching metadata saves one HTTP request
  • Downloads include automatic decompression

Configuration Requirements

Ensure the booksEndpoint is configured before calling this function:
  • getBookMetadata - Fetch metadata before downloading
  • getBook - Get book data as a JavaScript object without saving to disk
  • getCoverUrl - Generate the cover image URL for a book