epub

package
v0.0.0-...-2dbda58 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DCCreator

type DCCreator struct {
	ID    string // id attribute (used as refines target in EPUB 3)
	Value string
	Role  string // opf:role attribute (EPUB 2)
}

DCCreator represents a dc:creator element with optional opf:role.

type DCIdentifier

type DCIdentifier struct {
	ID    string
	Value string
}

DCIdentifier is a dc:identifier element with optional id attribute.

type DCTitle

type DCTitle struct {
	ID    string // id attribute (used as refines target in EPUB 3)
	Value string
}

DCTitle represents a dc:title element with optional id attribute.

type EPUB

type EPUB struct {
	Path    string
	ZipFile *zip.ReadCloser
	Files   map[string]*zip.File // path -> zip.File

	// Parsed from container.xml
	RootfilePath   string
	AllRootfiles   []Rootfile // all rootfile elements from container.xml
	ContainerLinks []string   // hrefs from <links> in container.xml
	ContainerData  []byte     // raw container.xml bytes

	// Parsed from OPF
	Package *Package

	// Raw OPF parse info (set during ParseOPF)
	OPFParseError error
	HasMetadata   bool
	HasManifest   bool
	HasSpine      bool
}

EPUB represents a parsed EPUB file.

func Open

func Open(filepath string) (*EPUB, error)

Open opens an EPUB file and parses its structure. The caller must call Close() when done.

func (*EPUB) Close

func (ep *EPUB) Close() error

Close releases the underlying zip reader.

func (*EPUB) OPFDir

func (ep *EPUB) OPFDir() string

OPFDir returns the directory containing the OPF file.

func (*EPUB) ParseContainer

func (ep *EPUB) ParseContainer() error

ParseContainer parses META-INF/container.xml and sets RootfilePath.

func (*EPUB) ParseOPF

func (ep *EPUB) ParseOPF() error

ParseOPF parses the OPF package document and populates ep.Package. It uses raw XML scanning to detect structural issues like missing elements.

func (*EPUB) ReadFile

func (ep *EPUB) ReadFile(name string) ([]byte, error)

ReadFile reads the contents of a file within the EPUB.

func (*EPUB) ResolveHref

func (ep *EPUB) ResolveHref(href string) string

ResolveHref resolves a relative href from the OPF file to a full path within the EPUB. Manifest hrefs are IRI-encoded (e.g. spaces as %20), but ZIP entry names use decoded forms, so we percent-decode before joining.

type GuideReference

type GuideReference struct {
	Type  string
	Title string
	Href  string
}

GuideReference represents a guide reference element in EPUB 2.

type ManifestItem

type ManifestItem struct {
	ID           string
	Href         string
	MediaType    string
	Properties   string
	Fallback     string
	HasID        bool   // false when id attribute is missing
	MediaOverlay string // media-overlay attribute
}

ManifestItem represents a single item in the OPF manifest.

type MetaRefines

type MetaRefines struct {
	ID       string // id attribute on the meta element itself
	Refines  string // the refines attribute value (e.g., "#id")
	Property string
	Value    string
}

MetaRefines represents a meta element with a refines attribute.

type Metadata

type Metadata struct {
	Titles       []DCTitle
	Identifiers  []DCIdentifier
	Languages    []string
	Modified     string // dcterms:modified value
	Dates        []string
	Sources      []string
	Creators     []DCCreator
	Contributors []DCCreator // dc:contributor elements (same structure as dc:creator)
	DCElementIDs []string    // id attributes from all dc:* elements (publisher, subject, description, etc.)
}

Metadata holds the OPF metadata section.

type Package

type Package struct {
	UniqueIdentifier         string
	Version                  string
	Dir                      string // dir attribute on package element
	Prefix                   string // prefix attribute on package element
	Metadata                 Metadata
	Manifest                 []ManifestItem
	Spine                    []SpineItemref
	SpineToc                 string // EPUB 2 spine toc attribute
	RenditionLayout          string // "pre-paginated" or "reflowable"
	RenditionFlow            string // rendition:flow property
	Guide                    []GuideReference
	HasGuide                 bool // whether a <guide> element was present
	ModifiedCount            int  // number of dcterms:modified meta elements
	RenditionOrientation     string
	RenditionSpread          string
	PageProgressionDirection string        // spine page-progression-direction attribute
	MetaRefines              []MetaRefines // meta elements with refines attribute
	MetaIDs                  []string      // id attributes from all meta elements in metadata
	ElementOrder             []string      // order of top-level OPF elements (metadata, manifest, spine, guide)
}

Package represents the OPF package document.

type Rootfile

type Rootfile struct {
	FullPath  string
	MediaType string
}

Rootfile represents a rootfile element from container.xml.

type SpineItemref

type SpineItemref struct {
	IDRef      string
	Properties string
	Linear     string // linear attribute value ("yes", "no", or empty)
}

SpineItemref represents a single itemref in the OPF spine.

Jump to

Keyboard shortcuts

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