epubgo

package module
v0.0.0-...-90dd5d7 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2016 License: LGPL-3.0 Imports: 9 Imported by: 4

README

A pure go implementation of epub file format.

Still on development.

Documentation

Overview

Package epubgo implements reading for epub ebook format.

A simple example of usage:

book, err := epub.Open("path/of/the/file.epub")
if err != nil {
	log.Panic(err)
}
defer book.Close()
title, _ := book.Metadata("title")
fmt.Println(title[0])

The pages of the book can be browsed with the SpineIterator:

it, err := book.Spine()
page := it.Open()
defer page.Close()
it.Next()

The index of the book can be browsed with the NavigationIterator:

it, err := book.Navigation()
it.Title()
it.Next()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Epub

type Epub struct {
	// contains filtered or unexported fields
}

Epub holds all the data of the ebook

func Load

func Load(r io.ReaderAt, size int64) (e *Epub, err error)

Load loads an epub from an io.ReaderAt

func Open

func Open(path string) (e *Epub, err error)

Open opens an existing epub

func (Epub) Close

func (e Epub) Close()

Close closes the epub file

func (Epub) Metadata

func (e Epub) Metadata(field string) ([]string, error)

Metadata returns the values of a metadata field

The valid field names are:

title, language, identifier, creator, subject, description, publisher,
contributor, date, type, format, source, relation, coverage, rights, meta

func (Epub) MetadataAttr

func (e Epub) MetadataAttr(field string) ([]map[string]string, error)

MetadataAttr returns the metadata attributes

Returns: an array of maps of each attribute and it's value. The array has the fields on the same order than the Metadata method.

func (Epub) MetadataFields

func (e Epub) MetadataFields() []string

MetadataFields retunrs the list of metadata fields pressent on the current epub

func (Epub) Navigation

func (e Epub) Navigation() (*NavigationIterator, error)

Navigation returns a navigation iterator

func (Epub) OpenFile

func (e Epub) OpenFile(name string) (io.ReadCloser, error)

OpenFile opens a file inside the epub

func (Epub) OpenFileId

func (e Epub) OpenFileId(id string) (io.ReadCloser, error)

OpenFileId opens a file from it's id

The id of the files often appears on metadata fields

func (Epub) Spine

func (e Epub) Spine() (*SpineIterator, error)

Spine returns a spine iterator

type NavigationIterator struct {
	// contains filtered or unexported fields
}

NavigationIterator is an iterator on the epub navigation index tree.

With it is possible to navigate throw the sections, subsections, ... of the epub.

func (nav NavigationIterator) HasChildren() bool

HasChildren returns whether the item has any children sections

func (nav NavigationIterator) HasParents() bool

HasParents returns whether the item has any parent sections

func (nav *NavigationIterator) In() error

In moves the iterator one level in on depth

Returns an error if it don't has children

func (nav NavigationIterator) IsFirst() bool

IsFirst returns whether the item is the first of the sections on the same depth level

func (nav NavigationIterator) IsLast() bool

IsLast returns whether the item is the last of the sections on the same depth level

func (nav *NavigationIterator) Next() error

Next advances the iterator to the next element on the same depth level

Returns an error if is the last

func (nav *NavigationIterator) Out() error

Out moves the iterator one level out on depth

Returns an error if it don't has parents

func (nav *NavigationIterator) Previous() error

Previous steps back the iterator to the previous element on the same depth level

Returns an error if is the first

func (nav NavigationIterator) Title() string

Title returns the title of the item on the iterator

func (nav NavigationIterator) URL() string

URL returns the url of the item on the iterator

It usually contains a path and a section link after a '#'. The path can be open with epub.OpenFile()

type SpineIterator

type SpineIterator struct {
	// contains filtered or unexported fields
}

SpineIterator is an iterator on the epub pages spine

With it is possible to navigate throw the pages of the epub.

func (SpineIterator) IsFirst

func (spine SpineIterator) IsFirst() bool

IsFirst returns whether the element is the first of the book

func (SpineIterator) IsLast

func (spine SpineIterator) IsLast() bool

IsLast returns whether the element is the last of the book

func (*SpineIterator) Next

func (spine *SpineIterator) Next() error

Next advances the iterator to the next element on the spine

Returns an error if is the last

func (SpineIterator) Open

func (spine SpineIterator) Open() (io.ReadCloser, error)

Open opens the file of the iterator

func (*SpineIterator) Previous

func (spine *SpineIterator) Previous() error

Previous steps back the iterator to the previous element on the spine

Returns an error if is the first

func (SpineIterator) URL

func (spine SpineIterator) URL() string

URL returns the url of the item on the iterator

Jump to

Keyboard shortcuts

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