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 ¶
- Variables
- func Validate(epub *Epub, condition *Condition) []error
- type Condition
- type Epub
- func (e Epub) Close()
- func (e Epub) Metadata(field string) ([]string, error)
- func (e Epub) MetadataAttr(field string) ([]map[string]string, error)
- func (e Epub) MetadataFields() []string
- func (e Epub) Navigation() (*NavigationIterator, error)
- func (e Epub) OpenFile(name string) (io.ReadCloser, error)
- func (e Epub) OpenFileId(id string) (io.ReadCloser, error)
- func (e Epub) Spine() (*SpineIterator, error)
- type NavigationIterator
- func (nav NavigationIterator) HasChildren() bool
- func (nav NavigationIterator) HasParents() bool
- func (nav *NavigationIterator) In() error
- func (nav NavigationIterator) IsFirst() bool
- func (nav NavigationIterator) IsLast() bool
- func (nav *NavigationIterator) Next() error
- func (nav *NavigationIterator) Out() error
- func (nav *NavigationIterator) Previous() error
- func (nav NavigationIterator) Title() string
- func (nav NavigationIterator) URL() string
- type SpineIterator
- func (spine SpineIterator) IsFirst() bool
- func (spine SpineIterator) IsLast() bool
- func (spine *SpineIterator) Next() error
- func (spine SpineIterator) Open() (io.ReadCloser, error)
- func (spine *SpineIterator) Previous() error
- func (spine SpineIterator) RootPath() string
- func (spine SpineIterator) URL() string
- type ValidateError
Constants ¶
This section is empty.
Variables ¶
var ErrLastEntry = errors.New("It is the last entry")
ErrLastEntry It is the last entry
var ValidateErrorTypeFileDamaged = 2
ValidateErrorTypeFileDamaged file เสียหาย
var ValidateErrorTypeFileNotFound = 1
ValidateErrorTypeFileNotFound file not found
var ValidateErrorTypeOverMaxImageSize = 3
ValidateErrorTypeOverMaxImageSize file too big
Functions ¶
Types ¶
type Condition ¶ added in v0.0.4
type Condition struct {
MaxImageSizeByte int64 //set to zero for no limit นี้คือ size ใน memory หลังจาก decode แล้วนะ
}
Condition condition for validate epub
type Epub ¶
type Epub struct {
// contains filtered or unexported fields
}
Epub holds all the data of the ebook
func (Epub) Metadata ¶
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 ¶
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 ¶
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
type NavigationIterator ¶
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 (NavigationIterator) HasChildren ¶
func (nav NavigationIterator) HasChildren() bool
HasChildren returns whether the item has any children sections
func (NavigationIterator) HasParents ¶
func (nav NavigationIterator) HasParents() bool
HasParents returns whether the item has any parent sections
func (*NavigationIterator) In ¶
func (nav *NavigationIterator) In() error
In moves the iterator one level in on depth
Returns an error if it don't has children
func (NavigationIterator) IsFirst ¶
func (nav NavigationIterator) IsFirst() bool
IsFirst returns whether the item is the first of the sections on the same depth level
func (NavigationIterator) IsLast ¶
func (nav NavigationIterator) IsLast() bool
IsLast returns whether the item is the last of the sections on the same depth level
func (*NavigationIterator) Next ¶
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 (*NavigationIterator) Out ¶
func (nav *NavigationIterator) Out() error
Out moves the iterator one level out on depth
Returns an error if it don't has parents
func (*NavigationIterator) Previous ¶
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 (NavigationIterator) Title ¶
func (nav NavigationIterator) Title() string
Title returns the title of the item on the iterator
func (NavigationIterator) URL ¶
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