epub

package
v0.0.0-...-e7f5644 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 7 Imported by: 11

README

epub

Minimal epub library written in Go

GoDoc

Installation

go get github.com/taylorskalyo/goreader/epub

Basic usage

import "github.com/taylorskalyo/goreader/epub"

rc, err := epub.OpenReader(os.Args[1])
if err != nil {
	panic(err)
}
defer rc.Close()

// The rootfile (content.opf) lists all of the contents of an epub file.
// There may be multiple rootfiles, although typically there is only one.
book := rc.Rootfiles[0]

// Print book title.
fmt.Println(book.Title)

// List the IDs of files in the book's spine.
for _, item := range book.Spine.Itemrefs {
	fmt.Println(item.ID)
}

Documentation

Overview

Package epub provides basic support for reading EPUB archives.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRootfile occurs when there are no rootfile entries found in
	// container.xml.
	ErrNoRootfile = errors.New("epub: no rootfile found in container")

	// ErrBadRootfile occurs when container.xml references a rootfile that does
	// not exist in the zip.
	ErrBadRootfile = errors.New("epub: container references non-existent rootfile")

	// ErrNoItemref occurrs when a content.opf contains a spine without any
	// itemref entries.
	ErrNoItemref = errors.New("epub: no itemrefs found in spine")

	// ErrBadItemref occurs when an itemref entry in content.opf references an
	// item that does not exist in the manifest.
	ErrBadItemref = errors.New("epub: itemref references non-existent item")

	// ErrBadManifest occurs when a manifest in content.opf references an item
	// that does not exist in the zip.
	ErrBadManifest = errors.New("epub: manifest references non-existent item")
)

Functions

This section is empty.

Types

type Container

type Container struct {
	Rootfiles []*Rootfile `xml:"rootfiles>rootfile"`
}

Container serves as a directory of Rootfiles.

type Item

type Item struct {
	ID        string `xml:"id,attr"`
	HREF      string `xml:"href,attr"`
	MediaType string `xml:"media-type,attr"`
	// contains filtered or unexported fields
}

Item represents a file stored in the epub.

func (*Item) Open

func (item *Item) Open() (r io.ReadCloser, err error)

Open returns a ReadCloser that provides access to the Items's contents. Multiple items may be read concurrently.

type Itemref

type Itemref struct {
	IDREF string `xml:"idref,attr"`
	*Item
}

Itemref points to an Item.

type Manifest

type Manifest struct {
	Items []Item `xml:"manifest>item"`
}

Manifest lists every file that is part of the epub.

type Metadata

type Metadata struct {
	Title       string `xml:"metadata>title"`
	Language    string `xml:"metadata>language"`
	Identifier  string `xml:"metadata>idenifier"`
	Creator     string `xml:"metadata>creator"`
	Contributor string `xml:"metadata>contributor"`
	Publisher   string `xml:"metadata>publisher"`
	Subject     string `xml:"metadata>subject"`
	Description string `xml:"metadata>description"`
	Event       []struct {
		Name string `xml:"event,attr"`
		Date string `xml:",innerxml"`
	} `xml:"metadata>date"`
	Type     string `xml:"metadata>type"`
	Format   string `xml:"metadata>format"`
	Source   string `xml:"metadata>source"`
	Relation string `xml:"metadata>relation"`
	Coverage string `xml:"metadata>coverage"`
	Rights   string `xml:"metadata>rights"`
}

Metadata contains publishing information about the epub.

type Package

type Package struct {
	Metadata
	Manifest
	Spine
}

Package represents an epub content.opf file.

type ReadCloser

type ReadCloser struct {
	Reader
	// contains filtered or unexported fields
}

ReadCloser represents a readable epub file that can be closed.

func OpenReader

func OpenReader(name string) (*ReadCloser, error)

OpenReader will open the epub file specified by name and return a ReadCloser.

func (*ReadCloser) Close

func (rc *ReadCloser) Close()

Close closes the epub file, rendering it unusable for I/O.

type Reader

type Reader struct {
	Container
	// contains filtered or unexported fields
}

Reader represents a readable epub file.

func NewReader

func NewReader(ra io.ReaderAt, size int64) (*Reader, error)

NewReader returns a new Reader reading from ra, which is assumed to have the given size in bytes.

type Rootfile

type Rootfile struct {
	FullPath string `xml:"full-path,attr"`
	Package
}

Rootfile contains the location of a content.opf package file.

type Spine

type Spine struct {
	Itemrefs []Itemref `xml:"spine>itemref"`
}

Spine defines the reading order of the epub documents.

Jump to

Keyboard shortcuts

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