Class: Cabriolet::HLP::QuickHelp::FileWriter
- Inherits:
-
Object
- Object
- Cabriolet::HLP::QuickHelp::FileWriter
- Defined in:
- lib/cabriolet/hlp/quickhelp/file_writer.rb
Overview
Writes QuickHelp files to disk
Instance Method Summary collapse
-
#initialize(io_system) ⇒ FileWriter
constructor
Initialize file writer.
-
#write_context_map(output_handle, context_map) ⇒ Integer
Write context map.
-
#write_context_strings(output_handle, contexts) ⇒ Integer
Write context strings.
-
#write_file_header(output_handle, header_info) ⇒ Integer
Write file header.
-
#write_quickhelp_file(output_handle, structure) ⇒ Integer
Write complete QuickHelp file.
-
#write_topic_index(output_handle, offsets) ⇒ Integer
Write topic index.
-
#write_topic_texts(output_handle, topics) ⇒ Integer
Write topic texts.
Constructor Details
#initialize(io_system) ⇒ FileWriter
Initialize file writer
11 12 13 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 11 def initialize(io_system) @io_system = io_system end |
Instance Method Details
#write_context_map(output_handle, context_map) ⇒ Integer
Write context map
103 104 105 106 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 103 def write_context_map(output_handle, context_map) map_data = context_map.pack("v*") @io_system.write(output_handle, map_data) end |
#write_context_strings(output_handle, contexts) ⇒ Integer
Write context strings
93 94 95 96 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 93 def write_context_strings(output_handle, contexts) data = contexts.map { |ctx| "#{ctx}\u0000" }.join @io_system.write(output_handle, data) end |
#write_file_header(output_handle, header_info) ⇒ Integer
Write file header
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 49 def write_file_header(output_handle, header_info) header = Binary::HLPStructures::FileHeader.new header.signature = Binary::HLPStructures::SIGNATURE header.version = header_info[:version] header.attributes = header_info[:attributes] header.control_character = header_info[:control_character] header.padding1 = 0 header.topic_count = header_info[:topic_count] header.context_count = header_info[:context_count] header.display_width = header_info[:display_width] header.padding2 = 0 header.predefined_ctx_count = header_info[:predefined_ctx_count] header.database_name = header_info[:database_name] header.reserved1 = 0 header.topic_index_offset = header_info[:offsets][:topic_index] header.context_strings_offset = header_info[:offsets][:context_strings] header.context_map_offset = header_info[:offsets][:context_map] header.keywords_offset = header_info[:offsets][:keywords] header.huffman_tree_offset = header_info[:offsets][:huffman_tree] header.topic_text_offset = header_info[:offsets][:topic_text] header.reserved2 = 0 header.reserved3 = 0 header.database_size = header_info[:offsets][:database_size] header_data = header.to_binary_s @io_system.write(output_handle, header_data) end |
#write_quickhelp_file(output_handle, structure) ⇒ Integer
Write complete QuickHelp file
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 20 def write_quickhelp_file(output_handle, structure) bytes_written = 0 # Write file header bytes_written += write_file_header(output_handle, structure[:header]) # Write topic index bytes_written += write_topic_index(output_handle, structure[:header][:offsets]) # Write context strings bytes_written += write_context_strings(output_handle, structure[:contexts]) # Write context map bytes_written += write_context_map(output_handle, structure[:context_map]) # Write topic texts bytes_written += write_topic_texts(output_handle, structure[:topics]) bytes_written end |
#write_topic_index(output_handle, offsets) ⇒ Integer
Write topic index
82 83 84 85 86 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 82 def write_topic_index(output_handle, offsets) # Write all topic offsets including end marker index_data = offsets[:topic_offsets].pack("V*") @io_system.write(output_handle, index_data) end |
#write_topic_texts(output_handle, topics) ⇒ Integer
Write topic texts
113 114 115 116 117 118 119 120 121 |
# File 'lib/cabriolet/hlp/quickhelp/file_writer.rb', line 113 def write_topic_texts(output_handle, topics) total_bytes = 0 topics.each do |topic| total_bytes += @io_system.write(output_handle, topic[:compressed]) end total_bytes end |