Coder Social home page Coder Social logo

gearthub / r2-streamer-swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from readium/r2-streamer-swift

0.0 1.0 0.0 135.93 MB

Repo for the Streamer implementation in Swift

License: BSD 3-Clause "New" or "Revised" License

Ruby 0.18% Shell 0.32% Swift 49.24% Objective-C 0.35% HTML 45.91% CSS 1.72% JavaScript 2.29%

r2-streamer-swift's Introduction

BSD-3 codebeat badge Carthage compatible JazzyDocumentation

R2-streamer-swift 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.

The project documentation is available here

Get started

Adding the library to your iOS project

Note: requires Swift 4.2 (and Xcode 10.1).

Carthage

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" ~> 1.0.7
  3. Run carthage update and add the appropriate framework.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To install R2Streamer with CocoaPods:

  1. Make sure CocoaPods is installed. (R2Streamer requires version 1.0.0 or greater.)

    # Using the default Ruby install will require you to use sudo when
    # installing and updating gems.
    [sudo] gem install cocoapods
  2. Update your Podfile to include the following:

    use_frameworks!
    
    target 'YourAppTargetName' do
        pod 'R2Streamer', :git => 'https://github.com/readium/r2-streamer-swift.git', '~> 1.0.7'
    end
  3. Run pod install --repo-update.

Import

In your Swift files :

// Swift source file

import R2Streamer

Parsing publications

EPUB

let parser = EpubParser()

CBZ

let parser = CbzParser()

Parsing
...
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:

publicationServer.remove(publication)

Or it's endpoint:

publicationServer.remove(at: "endpoint")

WebPub Manifest

For further informations see readium/webpub-manifest.

Pretty

publication.manifest()

Canonical

publication.manifestCanonical()


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.

Documentation

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.