Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for streaming ZIP packages over HTTP #537

Merged
merged 13 commits into from
Jan 19, 2025
Merged

Conversation

mickael-menu
Copy link
Member

@mickael-menu mickael-menu commented Jan 19, 2025

Added

Shared

  • Support for streaming ZIP packages over HTTP. This lets you open a remote EPUB, audiobook, or any other ZIP-based publication without needing to download it first.

⚠️ This does not support LCP-protected publications yet, unless they are stored on the server with the license embedded in the ZIP package.

A significant part of this feature depends on the work done in our fork of ZIPFoundation:

  • The access to ZIP data has been moved behind a new DataSource access layer, allowing us to integrate our Resource component.
  • The APIs have been updated to be async for compatibility with HTTP requests.

Further optimization was done on the Readium toolkit to reduce the number of HTTP requests sent to the server.

To avoid sending hundreds of consecutive small-range requests when extracting a ZIP entry, we make larger requests and cache the remaining data using a new implementation of BufferingResource. The buffer was set to 512 kB which seems to grant good performance with HTTP requests.

Before streaming each ZIP entry, ZIPFoundation must read the End of Central Directory Record (EOCDR) located at the end of the ZIP archive. ZIPFoundation finds the EOCDR by iterating over each byte from the end of the resource, which generates numerous small requests. To optimize this process, the tail of the ZIP resource is cached using a new TailCachingResource decorator, allowing it to be read only once. The cache size is based on the maximum EOCDR size of 65,557 bytes, as specified in the ZIP specification, plus an additional 76 bytes for the ZIP 64 EOCDR, according to the ZIPFoundation implementation.

Finally, for ZIP packages smaller than 5 MB, which includes most EPUB files, we load them entirely into memory.

☝️ Note that this feature only works with an HTTP server supporting byte range requests.

Here are some URLs that can be used to test this feature:

@mickael-menu mickael-menu merged commit 071bcb7 into develop Jan 19, 2025
5 checks passed
@mickael-menu mickael-menu deleted the zip-streaming branch January 19, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant