Light Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

peterbn/mobi

Repository files navigation

Mobi

Writer/Reader for Mobi format.

Note: All testing were done on Kindle Previewer (Windows) and Kindle Paperwhite (6th Gen)

Before You Start

  • This is more or less WIP. Use at your own risk.
  • This package was written for a specific task, thus there are certain limitations, such as:
    • img tags are ignored and not embedded.
    • TOC depth does not go beyond 1. Meaning for now you can only have chapters and sub-chapters. But sub-chaper can not have it's own sub-chapters.
  • HTML formatting is supported, but rendering is dependant on your eBook reader. (For Kindle see Supported HTML Tags in Book Content)
  • Cover images should be in JPG (I have not tested GIF, which sould be supported).
    • IMPORTANT: Images resized using image/jpeg package will not display (in Kindle) because JFIF APP0 marker segment is not generated by image/jpeg package.
  • Table of Content is automaticaly generated.

Usage

Writer

var m mobi.MobiWriter

m.Title("Book Title")
m.Compression(mobi.CompressionNone) // LZ77 compression is also possible using mobi.CompressionPalmDoc

// Add cover image
m.AddCover("data/cover.jpg", "data/thumbnail.jpg")

// Meta data
m.NewExthRecord(mobi.EXTH_DOCTYPE, "EBOK")
m.NewExthRecord(mobi.EXTH_AUTHOR, "Book Author Name")
// See exth.go for additional EXTH record IDs

// Add chapters and subchapters
ch1 := m.NewChapter("Chapter 1", []byte("Some text here"))
ch1.AddSubChapter("Chapter 1-1", []byte("Some text here"))
ch1.AddSubChapter("Chapter 1-2", []byte("Some text here"))

m.NewChapter("Chapter 2", []byte("Some text here")).AddSubChapter("Chapter 2-1", []byte("Some text here")).AddSubChapter("Chapter 2-2", []byte("Some text here"))
m.NewChapter("Chapter 3", []byte("Some text here")).AddSubChapter("Chapter 3-1", []byte("Some text here"))
m.NewChapter("Chapter 4", []byte("Some text here")).AddSubChapter("Chapter 4-1", []byte("Some text here"))

// Output MOBI File
file, err := os.Create(filename)
if err != nil {
panic(err)
}
m.WriteTo(file)
file.Close()

Compression

The mobi package implements two versions of the LZ77 compression algorithm. A fast version that uses a lookup data structure, which increases memory consumption and a low-memory version that does not use any lookup data structures, but is therefore slower.

The desired compression strategy can be chosen like this

mobi.SetCompressionStrategy(mobi.CompressFast) // Use lookup data structure (default)
mobi.SetCompressionStrategy(mobi.CompressLowMemory) // Choose low-memory consumption (slower)

Reader

For now, Reader does not give any useful information.

About

Golang package containing Writer/Reader for MOBI format

Resources

Readme

License

BSD-2-Clause license

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

  • Go 100.0%