-
Notifications
You must be signed in to change notification settings - Fork 127
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added
Shared
A significant part of this feature depends on the work done in our fork of ZIPFoundation:
DataSource
access layer, allowing us to integrate ourResource
component.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:
An audiobook containing a single audio file of 3+ hours, to test buffering
A large audiobook split in several chapters
A small audiobook split in several chapters
An EPUB