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 ¶
- Variables
- type Document
- func (d *Document) Close() error
- func (d *Document) Describe(ctx context.Context) (ivy.Info, error)
- func (d *Document) Page(ctx context.Context, n int) (ivy.Page, error)
- func (d *Document) PageCount(ctx context.Context) (int, error)
- func (d *Document) Previews(ctx context.Context) iter.Seq2[ivy.Preview, error]
- type Option
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) Describe ¶
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 ¶
Page satisfies the ivy.Pager interface. It lays out the book only as far as page n.