This page examines the process of "importing" an EPUB document into AxAp.


Here's a simplified guess at AxAp's approach to handling EPUB documents:

  • obtain an EPUB document
  • import it, if necessary
  • provide it to a browser


The "import" step clearly deserves some clarification. Basically, we're using Git to retain immutable cached versions of the reference data (e.g., document, generated file tree). We optimize on processing time and storage space by assuming that identical documents (per Git) will produce identical file trees. Here's some pseudo-code:

  • commit the document to Git
  • if any new data blobs were created:
    • unpack a copy of the document
    • commit the file tree to Git
    • add auxiliary files for browsers
    • commit the file tree again
    • return the commit ID to Sinatra

Although the unpacked HTML files can be displayed by a web browser, there is no support for indexing or navigation. Some of this can be provided by means of added HTML files; alternatively, JSON files can be supplied for use by a client-side app.

Note: Although there are many differences between static documents and remote web sites, they can be handled in a similar manner, using cached file trees, Git, etc.


As a minor detail, we need to get a (renamed) copy of the archive and unpack it into a directory tree. Here is some Bash code that does the trick:

$ base='programming-ruby-1-9-2-0_p2_0'
$ mkdir -p ex_pr/archives
$ cd ex_pr/archives
$ cp .../$base.epub $
$ unzip -d ../files $
$ cd ../files

For convenience, here is a Bash script:

# epub_unpack - unpack an EPUB document into a file tree
# Usage:
#   $ cd .../EPUB
#   $ mkdir -P <dir>/archives
#   $ cp .../<base>.epub <dir>/archives
#   $ epub_unpack <base> <dir>
# Written by Rich Morin, CFCL, 2016

  cd $dir/archives
  cp $base.epub $
  unzip -d ../tree $
  cd ../tree

This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r2 - 27 Oct 2016, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email