GithubHelp home page GithubHelp logo

zhnxin / mobi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from peterbn/mobi

1.0 0.0 0.0 2.02 MB

Golang package containing Writer/Reader for MOBI format

License: BSD 2-Clause "Simplified" License

Go 100.00%

mobi's Introduction

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.

mobi's People

Contributors

peterbn avatar 766b avatar zhnxin avatar

Stargazers

Nerten avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.