Module: KindleStrip

Extended by:
KindleStrip
Included in:
KindleStrip
Defined in:
lib/kindle_strip.rb,
lib/kindle_strip/version.rb

Constant Summary collapse

OFFSET_UNIQUE_ID_SEED =
68
OFFSET_NUMBER_OF_RECORDS =
76
OFFSET_RECORD_INFO =
78
VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#strip_srcs(input) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kindle_strip.rb', line 10

def strip_srcs(input)
  if input[0x3c, 8] != "BOOKMOBI"
    raise "MobiPocket marker not found"
  end
  num_records = uint16_be(input, OFFSET_NUMBER_OF_RECORDS)
  record0 = get_record0(input)
  srcs_start = uint32_be(record0, 0xe0)
  srcs_count = uint32_be(record0, 0xe4)
  if srcs_start == 0xffffffff || srcs_count == 0
    raise "File doesn't contain SRCS"
  end
  srcs_offset = uint32_be(input, OFFSET_RECORD_INFO + srcs_start * 8)
  srcs_length = uint32_be(input, OFFSET_RECORD_INFO + (srcs_start + srcs_count) * 8) - srcs_offset
  if input[srcs_offset, 4] != "SRCS"
    raise "SRCS section num does not point to SRCS"
  end

  output = new_header(input, num_records - srcs_count)
  output += new_record_infos(input, num_records, srcs_start, srcs_count, srcs_length)
  output += make_padding(output)
  output += new_records(input, srcs_offset, srcs_length)
  fix_record0(record0, srcs_start, srcs_count)
  set_record0(output, record0)
  output
end