Swiftpack.co -  readium/r2-streamer-swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Repo for the Streamer implementation in Swift
.package(url: "https://github.com/readium/r2-streamer-swift.git", from: "2.1.0")

BSD-3 codebeat badge Carthage compatible JazzyDocumentation

Readium Streamer aims at simplifying the usage of numeric publication by parsing and serving them. It takes the publication as input, and generates an accessible WebPubManifest/object as output.

Changes and releases are documented in the Changelog

Get started

Adding the library to your iOS project

Note: requires Swift 4.2 (and Xcode 10.1).


Carthage is a simple, decentralized dependency manager for Cocoa. To install R2Streamer with Carthage:

  1. Make sure Carthage is installed.

  2. Update your Cartfile to include the following:

    github "readium/r2-streamer-swift" "develop"
  3. Run:

  4. Add the appropriate framework.


In your Swift files :

// Swift source file

import R2Streamer

Parsing publications


let parser = EpubParser()


let parser = CbzParser()

var parseResult: PubBox

do {
    parseResult = try parser.parse(fileAtPath: path)
} catch {
    // `{Type}ParserError` exception handling

/// Get `Publication` from the `parseResult`
let publication = parseResult.publication

/// Access `Publication` content
let metadata = publication.metadata
let tableOfContent = publication.tableOfContent
let spineItems = publication.spine

You can now access your publications content programmatically. The Publication object is described in details here.

Built in HTTP server

Initializing the server

R2Streamer provides a local HTTP server called PublicationSever, this allow access to the resources of the Publication.

/// Instantiation of the HTTP server
guard let publicationServer = PublicationServer() else {
    // Error
Adding publications to the server

You can add your parsed publication to the server at the desired endpoints. (The endpoint parameter is optional, an UUID will be generated if let empty as below)

/// Adding a publication to the server (Using the above section variables)
do {
    try publicationServer.add(publication, with: container/* ,"customEndpoint" */)
} catch {
    // `PublicationServerError` exception handling

When a Publication is added to the server, a new 'self' Link is added to the Publication's links property. The Publication now know how to locate its resources over HTTP. See below for an example.

Accessing a Link resource from the server

The Publication is described using Links. Each link describe a resource from the publication in a Publication-relative way.

/// Accessing any `Link` resource over HTTP
let cover = publication.coverLink // Or `spineItems[x]`...

let coverUri = publication.uri(forLink: cover)
print(coverUri) // "http://{serverip}:{serverport}/{endpoint}/{`cover.href`}"
Removing a publication from the server

Using the Publication itself:


Or it's endpoint:

publicationServer.remove(at: "endpoint")

WebPub Manifest

For further informations see readium/webpub-manifest.





Supported formats:

EPUB 2/3/3.1- OEBPS - CBZ

Dependencies in this module

  • R2Shared : Contains the definitions of shared custom types used across the readium-2 Swift projects.
  • GCDWebServer A modern and lightweight GCD based HTTP 1.1 server designed to be embedded in OS X & iOS apps.
  • CryptoSwift Crypto related functions and helpers for Swift implemented in Swift.
  • Fuzi A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
  • Minizip Minizip framework wrapper for iOS, OSX, tvOS, and watchOS.


Jazzy is used to generate the project documentation. There are two script for building either the Public API documentation of the full documentation.

   ./generate_doc_public.sh    ./generate_doc_full.sh

The project documentation is available here


Stars: 19
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

7 weeks ago

Take a look at the migration guide


  • Support for Swift Package Manager (contributed by @stevenzeck).
  • EPUB publications implement a SearchService to search through the content.


  • The default EPUB positions service now uses the archive entry length when available. This is similar to how Adobe RMSDK generates page numbers.
    • To use the former strategy, create the Streamer with: Streamer(parsers: [EPUBParser(reflowablePositionsStrategy: .originalLength(pageLength: 1024))])


  • #208 Crash when reading obfuscated EPUB resources with an empty publication identifier.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics