epub

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2018 License: MIT Imports: 8 Imported by: 0

README

epub

A pure go implementation of epub file format.

Codeship Status for n3integration/epub codecov Go Report Card Documentation

Usage

import (
  "bytes"
  "fmt"
  "io"

  "github.com/n3integration/epub"
)

func main() {
+ // 1. Open the epub by passing its file path
  f := "some.epub"
  book, err := epub.Open(f)
  defer book.Close()

+ // 2. Iterate over book sections
  book.Each(func(title string, xhtml io.ReadCloser) {
+   // 3. Read and process section contents
    buf := new(bytes.Buffer)
    buf.ReadFrom(xhtml)

    fmt.Println("==========================================================")
    fmt.Println(title)
    fmt.Println("==========================================================")
    fmt.Println(buf.String())
  })
}

Reference

Documentation

Index

Constants

View Source
const EpubMimeType = "application/epub+zip"

Variables

This section is empty.

Functions

This section is empty.

Types

type Audio added in v0.2.0

type Audio struct {
	Src       string `xml:"src,attr"`
	ClipBegin string `xml:"clipBegin,attr"`
	ClipEnd   string `xml:"clipEnd,attr"`
}

Audio provides the audio element details

type Author added in v0.1.1

type Author struct {
	Data   string `xml:",chardata" json:"author"`
	FileAs string `xml:"file-as,attr" json:"file_as"`
	Role   string `xml:"role,attr" json:"role"`
	ID     string `xml:"id,attr" json:"id"`
}

Author author

type Body added in v0.2.0

type Body struct {
	TextRef string `xml:"textref,attr"`
	Seq     []Seq  `xml:"seq"`
	Par     []Par  `xml:"par"`
}

Body provides the SMIL body element

type Book

type Book struct {
	Ncx        Ncx        `json:"ncx"`
	Opf        Opf        `json:"opf"`
	Container  Container  `json:"-"`
	Mimetype   string     `json:"-"`
	Encryption Encryption `json:"-"`
	// contains filtered or unexported fields
}

Book provides the epub book contents

func Open

func Open(fn string) (*Book, error)

Open open a epub file

func OpenDir added in v0.2.0

func OpenDir(fn string) (*Book, error)

OpenDir opens an OPF file

func (*Book) Close

func (p *Book) Close()

Close file reader

func (*Book) Each added in v0.2.0

func (p *Book) Each(fn func(string, io.ReadCloser)) error

Each provides an iterator over each book section passing its title and contents

func (*Book) Files

func (p *Book) Files() []string

Files returns the list of resource files

func (*Book) GetSMIL added in v0.2.0

func (p *Book) GetSMIL(resource string) (*SMIL, error)

GetSMIL parses and returns the SMIL structure

func (*Book) Open

func (p *Book) Open(n string) (io.ReadCloser, error)

Open a resource file.

func (*Book) ZipReader added in v0.2.0

func (p *Book) ZipReader() *zip.ReadCloser

ZipReader returns the internal file descriptor

type CipherData added in v0.2.0

type CipherData struct {
	CipherReference CipherReference `xml:"CipherReference"`
}

CipherData provides the encryption cipher information

type CipherReference added in v0.2.0

type CipherReference struct {
	URI string `xml:"URI,attr"`
}

CipherReference provides the encryption

type Compression added in v0.2.0

type Compression struct {
	Method         string `xml:"Method,attr"`
	OriginalLength string `xml:"OriginalLength,attr"`
}

Compression provides encryption compression details

type Container

type Container struct {
	Rootfile Rootfile `xml:"rootfiles>rootfile" json:"rootfile"`
}

Container META-INF/container.xml file

type Content added in v0.1.1

type Content struct {
	Src string `xml:"src,attr" json:"src"`
}

Content nav-point content

type Date added in v0.1.1

type Date struct {
	Data  string `xml:",chardata" json:"data"`
	Event string `xml:"event,attr" json:"event"`
}

Date date

type EncryptedData added in v0.2.0

type EncryptedData struct {
	EncryptionMethod     EncryptionMethod     `xml:"EncryptionMethod"`
	KeyInfo              KeyInfo              `xml:"KeyInfo"`
	CipherData           CipherData           `xml:"CipherData"`
	EncryptionProperties []EncryptionProperty `xml:"EncryptionProperties>EncryptionProperty"`
}

EncryptedData provides encryption information

type Encryption added in v0.2.0

type Encryption struct {
	EncryptedData []EncryptedData `xml:"EncryptedData" json:"encrypted_data"`
}

Encryption encryption.xml

type EncryptionMethod added in v0.2.0

type EncryptionMethod struct {
	Algorithm string `xml:"Algorithm,attr"`
}

EncryptionMethod provides the encryption algorithm

type EncryptionProperty added in v0.2.0

type EncryptionProperty struct {
	Compression Compression `xml:"Compression"`
}

EncryptionProperty provides encryption compression information

type Identifier added in v0.1.1

type Identifier struct {
	Data   string `xml:",chardata" json:"data"`
	ID     string `xml:"id,attr" json:"id"`
	Scheme string `xml:"scheme,attr" json:"scheme"`
}

Identifier identifier

type KeyInfo added in v0.2.0

type KeyInfo struct {
	Resource string `xml:",chardata"`
}

KeyInfo provides the encryption key details

type Manifest added in v0.1.1

type Manifest struct {
	ID           string `xml:"id,attr" json:"id"`
	Href         string `xml:"href,attr" json:"href"`
	MediaType    string `xml:"media-type,attr" json:"type"`
	Fallback     string `xml:"media-fallback,attr" json:"fallback"`
	Properties   string `xml:"properties,attr" json:"properties"`
	MediaOverlay string `xml:"media-overlay,attr" json:"overlay"`
}

Manifest manifest

type Metadata added in v0.1.1

type Metadata struct {
	Title       []Title      `xml:"title" json:"title"`
	Language    []string     `xml:"language" json:"language"`
	Identifier  []Identifier `xml:"identifier" json:"identifier"`
	Creator     []Author     `xml:"creator" json:"creator"`
	Subject     []Subject    `xml:"subject" json:"subject"`
	Description []string     `xml:"description" json:"description"`
	Publisher   []string     `xml:"publisher" json:"publisher"`
	Contributor []Author     `xml:"contributor" json:"contributor"`
	Date        []Date       `xml:"date" json:"date"`
	Type        []string     `xml:"type" json:"type"`
	Format      []string     `xml:"format" json:"format"`
	Source      []string     `xml:"source" json:"source"`
	Relation    []string     `xml:"relation" json:"relation"`
	Coverage    []string     `xml:"coverage" json:"coverage"`
	Rights      []string     `xml:"rights" json:"rights"`
	Meta        []Metafield  `xml:"meta" json:"meta"`
	Guide       []Reference  `xml:"guide" json:"guide"`
}

Metadata provides epub metadata

type Metafield added in v0.1.1

type Metafield struct {
	Name     string `xml:"name,attr" json:"name"`
	Content  string `xml:"content,attr" json:"content"`
	Refine   string `xml:"refines,attr" json:"refines"`
	Property string `xml:"property,attr" json:"property"`
	Data     string `xml:",chardata" json:"data"`
	ID       string `xml:"id,attr" json:"id"`
	Lang     string `xml:"lang,attr" json:"lang"`
}

Metafield metafield

type NavPoint struct {
	Text        string     `xml:"navLabel>text" json:"text"`
	Content     Content    `xml:"content" json:"content"`
	Points      []NavPoint `xml:"navPoint" json:"points"`
	PlayerOrder int        `xml:"playOrder" json:"play_order"`
}

NavPoint nav point

type Ncx

type Ncx struct {
	Points   []NavPoint `xml:"navMap>navPoint" json:"points"`
	PageList PageList   `xml:"pageList" json:"page_list"`
}

Ncx OPS/toc.ncx

type Opf

type Opf struct {
	Metadata         Metadata   `xml:"metadata" json:"metadata"`
	Manifest         []Manifest `xml:"manifest>item" json:"manifest"`
	Spine            Spine      `xml:"spine" json:"spine"`
	UniqueIdentifier string     `xml:"unique-identifier,attr" json:"unique-identifier"`
	Dir              string     `xml:"dir,attr" json:"dir"`
	Version          string     `xml:"version,attr" json:"version"`
}

Opf content.opf

type PageList added in v0.2.0

type PageList struct {
	PageTarget []PageTarget `xml:"pageTarget" json:"page_targets"`
	Class      string       `xml:"class" json:"class"`
	ID         string       `xml:"id" json:"id"`
}

PageList page list

type PageTarget added in v0.2.0

type PageTarget struct {
	Text      string  `xml:"navLabel>text" json:"text"`
	Value     string  `xml:"value" json:"value"`
	Type      string  `xml:"type" json:"type"`
	PlayOrder int     `xml:"playOrder" json:"play_order"`
	Content   Content `xml:"content" json:"content"`
}

PageTarget page target

type Par added in v0.2.0

type Par struct {
	Text  Text  `xml:"text"`
	Audio Audio `xml:"audio"`
}

Par provides parallel SMIL elements

type Reference added in v0.2.0

type Reference struct {
	Href  string `xml:"href,attr" json:"href"`
	Title string `xml:"title,attr" json:"title"`
	Type  string `xml:"type,attr" json:"type"`
}

Reference reference in guide

type Rootfile added in v0.1.1

type Rootfile struct {
	Path    string `xml:"full-path,attr" json:"path"`
	Type    string `xml:"media-type,attr" json:"type"`
	Version string `xml:"version,attr" json:"version"`
}

Rootfile root file

type SMIL added in v0.2.0

type SMIL struct {
	Body Body `xml:"body"`
}

SMIL or Synchronized Multimedia Integration Language, wrapper

type Seq added in v0.2.0

type Seq struct {
	TextRef string `xml:"textref,attr"`
	Par     []Par  `xml:"par"`
	Seq     []Seq  `xml:"seq"`
}

Seq provides sequential SMIL elements

type Spine added in v0.1.1

type Spine struct {
	ID              string      `xml:"id,attr" json:"id"`
	Toc             string      `xml:"toc,attr" json:"toc"`
	PageProgression string      `xml:"page-progression-direction,attr" json:"progression"`
	Items           []SpineItem `xml:"itemref" json:"items"`
}

Spine spine

type SpineItem added in v0.1.1

type SpineItem struct {
	IDref      string `xml:"idref,attr" json:"id_ref"`
	Linear     string `xml:"linear,attr" json:"linear"`
	ID         string `xml:"id,attr" json:"id"`
	Properties string `xml:"properties,attr" json:"properties"`
}

SpineItem spine item

type Subject added in v0.2.0

type Subject struct {
	Data      string `xml:",chardata" json:"data"`
	Term      string `xml:"term,attr" json:"term"`
	Authority string `xml:"authority,attr" json:"authority"`
	Lang      string `xml:"lang,attr" json:"lang"`
}

Subject subject

type Text added in v0.2.0

type Text struct {
	Src string `xml:"src,attr"`
}

Text provides the source text

type Title added in v0.2.0

type Title struct {
	Data string `xml:",chardata" json:"data"`
	ID   string `xml:"id,attr" json:"id"`
	Lang string `xml:"lang,attr" json:"lang"`
	Dir  string `xml:"dir" json:"dir"`
}

Title title

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL