fb2

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fb2 opens FictionBook 2 files: an .fb2 file, which is XML, and a zip archive that holds one, such as .fb2.zip or .fbz. A zip archive whose entries ZipCrypto or the AES of WinZip encrypts opens with the password of ivy.Config, or with its function PasswordFunc (D12).

The package converts the body of the book into one XHTML document with a style sheet, for the layout of ivy (D10, D21). The images of the book are in its binary elements, as base64, and the package decodes them into the files that the document links to. The cover is the preview. The layout puts the document on the pages of an ebook, and Page lays it out only as far as the page that a program asks for. As in calibre, the first page shows the cover image, scaled to fit the page.

The package reads UTF-8, UTF-16 and each encoding of the WHATWG Encoding Standard, such as windows-1251 and KOI8-R. It reads a file of another encoding as UTF-8, and logs a warning. It does not apply the style sheet that a file can carry, because that style sheet names the elements of FictionBook, and not those of the XHTML document.

Index

Constants

This section is empty.

Variables

View Source
var Format = ivy.Format{
	Name:  "fb2",
	Mimes: []string{"application/x-fictionbook+xml", "application/x-zip-compressed-fb2"},
	Exts:  []string{"fb2", "fbz"},
	Open: func(ctx context.Context, src ivy.Source, cfg ivy.Config) (ivy.Document, error) {
		return Open(ctx, src, WithConfig(cfg))
	},
}

Format describes the package for the registry of a program. A zip archive of a FictionBook file often has the extension .fb2.zip, which the registry cannot name, so a program finds it by its mime type or by its content.

Functions

This section is empty.

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is an open FictionBook file.

func Open

func Open(ctx context.Context, src ivy.Source, opts ...Option) (d *Document, err error)

Open opens a FictionBook file, or a zip archive that holds one. It parses the XML of the book. It returns an error that wraps ivy.ErrFormat if src is not a FictionBook file, and one that wraps ivy.ErrPassword if no password opens an encrypted zip archive.

func (*Document) Close

func (d *Document) Close() error

Close satisfies the ivy.Document interface.

func (*Document) Describe

func (d *Document) Describe(ctx context.Context) (ivy.Info, error)

Describe satisfies the ivy.Describer interface. It reads the title-info, the document-info and the publish-info of the description. The date of the title-info is the creation date. ivy.Info has no field for the annotation, so the annotation is the start of the XHTML document instead.

func (*Document) Page

func (d *Document) Page(ctx context.Context, n int) (ivy.Page, error)

Page satisfies the ivy.Pager interface. It lays out the book only as far as page n.

func (*Document) PageCount

func (d *Document) PageCount(ctx context.Context) (int, error)

PageCount satisfies the ivy.Pager interface. It lays out the whole book on its first call.

func (*Document) Previews

func (d *Document) Previews(ctx context.Context) iter.Seq2[ivy.Preview, error]

Previews satisfies the ivy.Previewer interface. The preview is the image of the coverpage.

type Option

type Option func(*options)

Option is an option of Open.

func WithConfig

func WithConfig(cfg ivy.Config) Option

WithConfig sets the configuration that every format shares.

Jump to

Keyboard shortcuts

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