class KindleCG::Ebook::Sectionizer
Attributes
file[RW]
header[RW]
identity[RW]
sections[RW]
Public Class Methods
new(file, perm)
click to toggle source
# File lib/KindleCG/ebook/sectionizer.rb, line 7 def initialize(file, perm) @file = File.open(file, perm) @header = @file.read(78) @sections = split_sections(@header, @file) end
Public Instance Methods
load_section(section)
click to toggle source
# File lib/KindleCG/ebook/sectionizer.rb, line 13 def load_section(section) before, after = @sections[section..section+2] @file.seek(before) @file.read(after - before) end
Private Instance Methods
split_sections(header, file)
click to toggle source
# File lib/KindleCG/ebook/sectionizer.rb, line 25 def split_sections(header, file) num_sections, = header[76..-1].unpack 'S!>' raw_sections = file.read(num_sections*8) sections_unpacked = raw_sections.unpack ("L>%d" % (num_sections*2)) sections_unpacked.values_at(*(0..sections_unpacked.size).step(2)).compact + [0xfffffff] end