records

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package records contains facilities to create MOBI formatted books.

Index

Constants

View Source
const NullPaddingLength = 8192 // 0x2000
View Source
const TextRecordMaxSize = 4096 // 0x1000

Variables

This section is empty.

Functions

func ChunkIndexRecord

func ChunkIndexRecord(info []ChunkInfo) (IndexRecord, CNCXRecord)

func NCXIndexRecord

func NCXIndexRecord(info []ChapterInfo) (IndexRecord, CNCXRecord)

func To32

func To32(i int) string

Types

type CNCXRecord

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

func (CNCXRecord) Length

func (r CNCXRecord) Length() int

func (CNCXRecord) LengthNoPadding

func (r CNCXRecord) LengthNoPadding() int

func (CNCXRecord) Write

func (r CNCXRecord) Write(w io.Writer) error

type ChapterInfo

type ChapterInfo struct {
	Title  string
	Start  int
	Length int
}

type ChunkInfo

type ChunkInfo struct {
	PreStart      int
	PreLength     int
	ContentStart  int
	ContentLength int
}

type EXTHEntry

type EXTHEntry struct {
	EntryType t.EXTHEntryType
	Data      []byte
}

func NewEXTHEntry

func NewEXTHEntry(tp t.EXTHEntryType, data []byte) EXTHEntry

func (EXTHEntry) Length

func (e EXTHEntry) Length() int

func (EXTHEntry) Write

func (e EXTHEntry) Write(w io.Writer) error

type EXTHSection

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

func NewEXTHSection

func NewEXTHSection() EXTHSection

func (*EXTHSection) AddInt

func (e *EXTHSection) AddInt(tp t.EXTHEntryType, is ...int)

func (*EXTHSection) AddString

func (e *EXTHSection) AddString(tp t.EXTHEntryType, ss ...string)

func (EXTHSection) Length

func (e EXTHSection) Length() int

func (EXTHSection) LengthWithoutPadding

func (e EXTHSection) LengthWithoutPadding() int

func (EXTHSection) Write

func (e EXTHSection) Write(w io.Writer) error

type FDSTRecord

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

func NewFDSTRecord

func NewFDSTRecord(flows ...string) FDSTRecord

func (FDSTRecord) Write

func (r FDSTRecord) Write(w io.Writer) error

type ImageRecord

type ImageRecord struct {
	Img  image.Image
	Ext  string
	Data []byte
}

func (ImageRecord) Write

func (r ImageRecord) Write(w io.Writer) error
func NewImageRecord(img image.Image) ImageRecord {
	return ImageRecord{
		Img: img,
	}
}

type IndexRecord

type IndexRecord struct {
	Type          uint32
	HeaderType    uint32
	TAGXTable     t.TAGXTagTable
	IDXTEntries   [][]byte
	SubEntryCount uint32
	CNCXCount     uint32
}

func ChunkHeaderIndexRecord

func ChunkHeaderIndexRecord(lastPos int, entryCount int) IndexRecord

func NCXHeaderIndexRecord

func NCXHeaderIndexRecord(entryCount int) IndexRecord

func SkeletonHeaderIndexRecord

func SkeletonHeaderIndexRecord(entryCount int) IndexRecord

func SkeletonIndexRecord

func SkeletonIndexRecord(info []ChunkInfo) IndexRecord

func (IndexRecord) Length

func (r IndexRecord) Length() int

func (IndexRecord) LengthNoPadding

func (r IndexRecord) LengthNoPadding() int

func (IndexRecord) Write

func (r IndexRecord) Write(w io.Writer) error

type NullRecord

type NullRecord struct {
	PalmDocHeader t.PalmDocHeader
	MOBIHeader    t.KF8Header
	FullName      string
	EXTHSection   EXTHSection
}

func NewNullRecord

func NewNullRecord(name string) NullRecord

func (NullRecord) Write

func (n NullRecord) Write(w io.Writer) error

type SequenceData

type SequenceData struct {
	Index                     int
	FlagFirstOfNotFirstStrand bool
	FlagTBSType               int
	FlagNumSiblings           byte
	FlagDoesSpan              bool
}

SequenceData is the indexing data that represents one chapter of an arbitrary level in the trailing byte sequence of a text record. If the chapter and its siblings do not have sub-chapters, its siblings are also combined into the sequence.

type StrandData

type StrandData SequenceData

StrandData is the indexing data that represents one hierarchy of chapters and sub-chapters in the trailing byte sequence of a text record. This data would normally be separated into multiple strands and sequences but this implementation does not support sub-chapters meaning a strand must contain exactly one sequence and the indexing data must consist of either one or zero strands.

func (StrandData) Encode

func (sd StrandData) Encode() []byte

type TextRecord

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

func NewTextRecord

func NewTextRecord(s string, trail TrailingData) TextRecord

func (TextRecord) Length

func (r TextRecord) Length() int

func (TextRecord) Write

func (r TextRecord) Write(w io.Writer) error

type TrailProvider

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

func NewTrailProvider

func NewTrailProvider(chapters []ChapterInfo) TrailProvider

type TrailingData

type TrailingData struct {
	Multibyte byte
	Strands   *StrandData
}

TrailingData represents is the trailing entries that are appended to every text record as indicated by the extra data bitflags in the MOBI header. This implementation only supports flags 0b11 meaning entries for multibyte overlap and indexing data.

func Get

func Get(end int, from, to int) TrailingData
func (s *TrailProvider) Get(from, to int) TrailingData {
	strands := TrailingData{Multibyte: 0}
	for i, chap := range s.chapters {
		end := chap.Start + chap.Length
		if chap.Start < from && end > to {
			strands.Strands = &StrandData{
				Index:        i,
				FlagTBSType:  8,
				FlagDoesSpan: true,
			}
			break
		}

		if chap.Start >= from && chap.Start <= to || end >= from && end <= to {
			if strands.Strands == nil {
				strands.Strands = &StrandData{
					Index:        i,
					FlagTBSType:  8,
					FlagDoesSpan: false,
				}
			}
			strands.Strands.FlagNumSiblings++
		}
	}

	return strands
}

func (TrailingData) Encode

func (td TrailingData) Encode() []byte

Jump to

Keyboard shortcuts

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