Class: Cabriolet::HLP::WinHelp::Compressor
- Inherits:
-
Object
- Object
- Cabriolet::HLP::WinHelp::Compressor
- Defined in:
- lib/cabriolet/hlp/winhelp/compressor.rb
Overview
Compressor creates Windows Help (.HLP) files
Creates WinHelp 3.x and 4.x format files with Zeck LZ77 compression. Supports creating |SYSTEM, |TOPIC, and other internal files.
Constant Summary collapse
- BLOCK_SIZE =
Default block size for WinHelp files (4096 bytes)
4096
Instance Attribute Summary collapse
-
#io_system ⇒ Object
readonly
Returns the value of attribute io_system.
Instance Method Summary collapse
-
#add_internal_file(name, data) ⇒ void
Add an internal file to the WinHelp archive.
-
#add_system_file(**options) ⇒ void
Add |SYSTEM file with metadata.
-
#add_topic_file(topics, compress: true) ⇒ void
Add |TOPIC file with compressed topics.
-
#generate(output_file, **options) ⇒ Integer
Generate WinHelp file.
-
#initialize(io_system = nil) ⇒ Compressor
constructor
Initialize compressor.
Constructor Details
#initialize(io_system = nil) ⇒ Compressor
Initialize compressor
22 23 24 25 26 |
# File 'lib/cabriolet/hlp/winhelp/compressor.rb', line 22 def initialize(io_system = nil) @io_system = io_system || System::IOSystem.new @internal_files = {} @version = :winhelp3 end |
Instance Attribute Details
#io_system ⇒ Object (readonly)
Returns the value of attribute io_system.
14 15 16 |
# File 'lib/cabriolet/hlp/winhelp/compressor.rb', line 14 def io_system @io_system end |
Instance Method Details
#add_internal_file(name, data) ⇒ void
This method returns an undefined value.
Add an internal file to the WinHelp archive
33 34 35 |
# File 'lib/cabriolet/hlp/winhelp/compressor.rb', line 33 def add_internal_file(name, data) @internal_files[name] = data end |
#add_system_file(**options) ⇒ void
This method returns an undefined value.
Add |SYSTEM file with metadata
44 45 46 47 |
# File 'lib/cabriolet/hlp/winhelp/compressor.rb', line 44 def add_system_file(**) system_data = build_system_file() add_internal_file("|SYSTEM", system_data) end |
#add_topic_file(topics, compress: true) ⇒ void
This method returns an undefined value.
Add |TOPIC file with compressed topics
54 55 56 57 |
# File 'lib/cabriolet/hlp/winhelp/compressor.rb', line 54 def add_topic_file(topics, compress: true) topic_data = build_topic_file(topics, compress) add_internal_file("|TOPIC", topic_data) end |
#generate(output_file, **options) ⇒ Integer
Generate WinHelp file
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cabriolet/hlp/winhelp/compressor.rb', line 65 def generate(output_file, **) @version = .fetch(:version, :winhelp3) if @internal_files.empty? raise ArgumentError, "No internal files added" end raise ArgumentError, "Invalid version" unless i[winhelp3 winhelp4].include?(@version) # Build structure structure = build_structure # Write to file output_handle = @io_system.open(output_file, Constants::MODE_WRITE) begin write_winhelp_file(output_handle, structure) ensure @io_system.close(output_handle) end end |