epub

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

Epub parser

This parser only supports epub version 3.0 so far. This parser also only reads MetaData and Manifest.

How to use?
binaryFile, err := os.ReadFile("./test_epub_v3_0.epub")
if err != nil {
    println(err.Error())
	return;
}
zipReader, err := zip.NewReader(bytes.NewReader(binaryFile), int64(len(binaryFile)))
if err != nil {
    println(err.Error())
	return;
}
book, err := OpenBook(zipReader)
if err != nil {
    println(err.Error())
	return;
}

After that, all metadata and manifest data can be found in the book Object

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	Opf       Package
	Container Container
	ZipReader *zip.Reader
}

func OpenBook

func OpenBook(reader *zip.Reader) (*Book, error)

func (*Book) Open

func (book *Book) Open(fileName string) (io.ReadCloser, error)

type Container

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

type DefaultAttributes

type DefaultAttributes struct {
	Id   string `xml:"id,attr,omitempty"`
	Dir  string `xml:"dir,attr,omitempty"`
	Lang string `xml:"lang,attr,omitempty"`
	Text string `xml:",chardata"`
}

type ID

type ID struct {
	Id   string `xml:"id,attr,omitempty"`
	Text string `xml:",chardata"`
}

type Item added in v1.1.0

type Item struct {
	Id           string `xml:"id,attr"`
	Href         string `xml:"href,attr"`
	MediaType    string `xml:"media-type,attr"`
	Fallback     string `xml:"fallback,attr,omitempty"`
	MediaOverlay string `xml:"media-overlay,attr,omitempty"`
	Properties   string `xml:"properties,attr,omitempty"`
}
type Link struct {
	Href       string `xml:"href,attr"`
	Rel        string `xml:"rel,attr"`
	Id         string `xml:"id,attr,omitempty"`
	MediaType  string `xml:"media-type,attr,omitempty"`
	Properties string `xml:"properties,attr,omitempty"`
	Refines    string `xml:"refines,attr,omitempty"`
}

type Manifest added in v1.1.0

type Manifest struct {
	Id   string  `xml:"id,attr,omitempty"`
	Item *[]Item `xml:"item"`
}

type Meta

type Meta struct {
	Id       string `xml:"id,attr,omitempty"`
	Dir      string `xml:"dir,attr,omitempty"`
	Lang     string `xml:"lang,attr,omitempty"`
	Property string `xml:"property,attr,omitempty"` //omitempty because the deprecated meta has no property
	Refines  string `xml:"refines,attr,omitempty"`
	Scheme   string `xml:"scheme,attr,omitempty"`
	Name     string `xml:"name,attr,omitempty"`    //deprecated
	Content  string `xml:"content,attr,omitempty"` //deprecated
	Text     string `xml:",chardata"`
}

type Metadata

type Metadata struct {
	Identifier  *[]ID                `xml:"identifier"`
	Language    *[]ID                `xml:"language"`
	Title       *[]DefaultAttributes `xml:"title"`
	Meta        *[]Meta              `xml:"meta"`
	Date        *[]ID                `xml:"date,omitempty"`
	Type        *[]ID                `xml:"type,omitempty"`
	Contributor *[]DefaultAttributes `xml:"contributor,omitempty"`
	Coverage    *[]DefaultAttributes `xml:"coverage,omitempty"`
	Creator     *[]DefaultAttributes `xml:"creator,omitempty"`
	Description *[]DefaultAttributes `xml:"description,omitempty"`
	Publisher   *[]DefaultAttributes `xml:"publisher,omitempty"`
	Relation    *[]DefaultAttributes `xml:"relation,omitempty"`
	Rights      *[]DefaultAttributes `xml:"rights,omitempty"`
	Subject     *[]DefaultAttributes `xml:"subject,omitempty"`
	Link        *[]Link              `xml:"link,omitempty"`
}

type Package

type Package struct {
	XMLName          xml.Name  `xml:"package"`
	Metadata         *Metadata `xml:"metadata"`
	Manifest         *Manifest `xml:"manifest"`
	Version          string    `xml:"version,attr"`
	UniqueIdentifier string    `xml:"unique-identifier,attr"`
	ID               string    `xml:"id,attr,omitempty"`
	Prefix           string    `xml:"prefix,attr,omitempty"`
	Lang             string    `xml:"lang,attr,omitempty"`
	Dir              string    `xml:"dir,attr,omitempty"`
}

type Rootfile

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

Jump to

Keyboard shortcuts

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