Documentation
¶
Overview ¶
Package epub provides support for reading, writing, and validating EPUB files.
Reading ¶
Use Open for repeated access to content items within a single archive; the file is kept open between calls. Use OpenPackage for one-shot access to the OPF metadata, OpenTOC for the table of contents, or OpenContainer when you only need the rootfile path.
Writing ¶
Use Write to encode a Book value as a valid EPUB 3 archive.
Validation ¶
Use Validate to check a parsed Package against the structural rules for its EPUB version.
Index ¶
- func Write(dst io.Writer, book Book) error
- type Book
- type Container
- type ContentItem
- type FileNotFoundError
- type Item
- type ItemNotFoundError
- type MalformedContainerError
- type Metadata
- type MissingMetadataError
- type MissingNavElementError
- type MissingTOCError
- type NavPoint
- type Package
- type Reader
- type SpineItem
- type UnsupportedVersionError
- type Violation
- type ViolationCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Book ¶
type Book struct {
Metadata Metadata `json:"metadata"` // bibliographic metadata written to the OPF <metadata> element
Items []ContentItem `json:"items"` // content files added to the manifest and stored in the ZIP
Spine []string `json:"spine"` // IDs of Items in reading order
}
Book is the input to Write: bibliographic metadata, content items, and the spine reading order.
type Container ¶
type Container struct {
// RootfilePath is the path within the ZIP to the root OPF document,
// e.g. "OEBPS/content.opf".
RootfilePath string `json:"rootfile_path"`
}
Container represents a parsed EPUB container (META-INF/container.xml).
func OpenContainer ¶
OpenContainer opens the .epub file at path and parses its container, returning the location of the root OPF document.
type ContentItem ¶
type ContentItem struct {
ID string `json:"id"` // manifest item id attribute; must be unique within the Book
Href string `json:"href"` // path relative to the OPF document, e.g. "chapter1.xhtml"
MediaType string `json:"media_type"` // MIME type, e.g. "application/xhtml+xml"
Properties string `json:"properties,omitempty"` // space-separated EPUB 3 properties, e.g. "nav"
Content []byte `json:"content"` // raw file bytes written into the ZIP
}
ContentItem is one content file to be written into the EPUB manifest and ZIP. Href is relative to the OPF document (e.g. "chapter1.xhtml"); Write stores it under OEBPS/ in the ZIP.
type FileNotFoundError ¶
type FileNotFoundError struct {
Path string
}
FileNotFoundError is returned when a required file is absent from the EPUB ZIP archive. Path is the ZIP-relative path that was expected.
func (*FileNotFoundError) Error ¶
func (e *FileNotFoundError) Error() string
type Item ¶
type Item struct {
ID string `json:"id"` // manifest item id attribute
Href string `json:"href"` // relative to the OPF document's directory
MediaType string `json:"media_type"` // e.g. "application/xhtml+xml", "image/jpeg"
// Properties contains space-separated property values (EPUB 3 only, e.g. "nav", "cover-image").
// Empty for EPUB 2 items.
Properties string `json:"properties,omitempty"`
}
Item is an entry in the OPF manifest.
type ItemNotFoundError ¶
type ItemNotFoundError struct {
ID string // manifest item id attribute
Href string // ZIP-relative path that was expected
}
ItemNotFoundError is returned by Reader.ReadItem when the manifest item's content file is absent from the ZIP archive.
func (*ItemNotFoundError) Error ¶
func (e *ItemNotFoundError) Error() string
type MalformedContainerError ¶
type MalformedContainerError struct{}
MalformedContainerError is returned when META-INF/container.xml contains no usable rootfile entry.
func (*MalformedContainerError) Error ¶
func (e *MalformedContainerError) Error() string
type Metadata ¶
type Metadata struct {
Title string `json:"title"` // dc:title
Authors []string `json:"authors,omitempty"` // dc:creator values, in document order
Language string `json:"language"` // dc:language (BCP 47 tag, e.g. "en")
Identifier string `json:"identifier"` // dc:identifier matching unique-identifier, or first dc:identifier
PublicationDate string `json:"publication_date,omitempty"` // "YYYY-MM-DD" or "YYYY" as written in the file; empty if absent
}
Metadata holds Dublin Core bibliographic information from the OPF.
type MissingMetadataError ¶
type MissingMetadataError struct {
Field string
}
MissingMetadataError is returned by Write when a required metadata field is empty. Field is the name of the missing field (e.g. "title").
func (*MissingMetadataError) Error ¶
func (e *MissingMetadataError) Error() string
type MissingNavElementError ¶
type MissingNavElementError struct{}
MissingNavElementError is returned when the EPUB 3 navigation document contains no <nav epub:type="toc"> element.
func (*MissingNavElementError) Error ¶
func (e *MissingNavElementError) Error() string
type MissingTOCError ¶
type MissingTOCError struct{}
MissingTOCError is returned when neither an EPUB 3 navigation document nor an EPUB 2 NCX item is present in the OPF manifest.
func (*MissingTOCError) Error ¶
func (e *MissingTOCError) Error() string
type NavPoint ¶
type NavPoint struct {
}
NavPoint is one entry in the table of contents. Children represent nested sections.
type Package ¶
type Package struct {
Version string `json:"version"` // e.g. "2.0" or "3.0", as written in the OPF
Metadata Metadata `json:"metadata"` // bibliographic metadata from the OPF <metadata> element
Manifest []Item `json:"manifest"` // all items declared in the OPF <manifest>
Spine []SpineItem `json:"spine"` // reading order declared in the OPF <spine>
}
Package is the parsed contents of an OPF package document.
func DecodePackageV2 ¶
DecodePackageV2 parses r as an EPUB 2 OPF document. It ignores the version attribute; use this when you already know the content is EPUB 2.
func DecodePackageV3 ¶
DecodePackageV3 parses r as an EPUB 3 OPF document. It ignores the version attribute; use this when you already know the content is EPUB 3.
func OpenPackage ¶
OpenPackage opens the .epub file at path, locates the OPF document via the container, and returns the parsed Package.
type Reader ¶
type Reader struct {
// Package is the parsed OPF document for the open EPUB.
Package *Package
// contains filtered or unexported fields
}
Reader holds an open EPUB file and its parsed Package, allowing content items to be read without reopening the archive on each call. The caller must call Close when done. Reader is safe for concurrent use.
func Open ¶
Open opens the .epub file at path, parses its package document, and returns a Reader. The caller must call Close when done to release the file handle.
type SpineItem ¶
type SpineItem struct {
IDRef string `json:"id_ref"` // references a manifest item by its ID
Linear bool `json:"linear"` // false only when the OPF explicitly sets linear="no"
}
SpineItem is one entry in the OPF spine, identifying a manifest item by ID.
type UnsupportedVersionError ¶
type UnsupportedVersionError struct {
Version string // the version string from the OPF version attribute
Path string // path to the OPF document within the EPUB archive
}
UnsupportedVersionError is returned when an OPF document declares a version that this package does not recognise.
func (*UnsupportedVersionError) Error ¶
func (e *UnsupportedVersionError) Error() string
type Violation ¶
type Violation struct {
Code ViolationCode `json:"code"` // machine-readable rule identifier
Message string `json:"message"` // human-readable description of the violation
}
Violation describes a single structural rule violation in a Package.
type ViolationCode ¶
type ViolationCode string
ViolationCode identifies the structural rule that was violated.
const ( // Metadata violations. ViolationMissingTitle ViolationCode = "missing-title" ViolationMissingLanguage ViolationCode = "missing-language" ViolationMissingIdentifier ViolationCode = "missing-identifier" // Manifest violations. ViolationEmptyManifest ViolationCode = "empty-manifest" ViolationMissingItemID ViolationCode = "missing-item-id" ViolationMissingItemHref ViolationCode = "missing-item-href" ViolationMissingItemMediaType ViolationCode = "missing-item-media-type" ViolationDuplicateItemID ViolationCode = "duplicate-item-id" ViolationDuplicateItemHref ViolationCode = "duplicate-item-href" // Spine violations. ViolationEmptySpine ViolationCode = "empty-spine" ViolationBrokenSpineIDRef ViolationCode = "broken-spine-idref" // Version-specific structural violations. ViolationMissingNCX ViolationCode = "missing-ncx" // EPUB 2: NCX document required )
Directories
¶
| Path | Synopsis |
|---|---|
|
tools
|
|
|
commit-msg
command
Validates a commit message against the Conventional Commits specification using the rules from @commitlint/config-conventional.
|
Validates a commit message against the Conventional Commits specification using the rules from @commitlint/config-conventional. |
|
semver
command
Creates a semver git tag.
|
Creates a semver git tag. |