Class: Cabriolet::CAB::Compressor
- Inherits:
-
Object
- Object
- Cabriolet::CAB::Compressor
- Defined in:
- lib/cabriolet/cab/compressor.rb
Overview
Compressor creates CAB files from source files rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#cabinet_index ⇒ Object
readonly
Returns the value of attribute cabinet_index.
-
#compression ⇒ Object
readonly
Returns the value of attribute compression.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#io_system ⇒ Object
readonly
Returns the value of attribute io_system.
-
#set_id ⇒ Object
readonly
Returns the value of attribute set_id.
Instance Method Summary collapse
-
#add_file(source_path, cab_path = nil) ⇒ void
Add a file to the cabinet.
-
#generate(output_file, **options) ⇒ Integer
Generate the cabinet file.
-
#initialize(io_system = nil) ⇒ Compressor
constructor
Initialize a new compressor.
Constructor Details
#initialize(io_system = nil) ⇒ Compressor
Initialize a new compressor
13 14 15 16 17 18 19 |
# File 'lib/cabriolet/cab/compressor.rb', line 13 def initialize(io_system = nil) @io_system = io_system || System::IOSystem.new @files = [] @compression = :mszip @set_id = rand(0xFFFF) @cabinet_index = 0 end |
Instance Attribute Details
#cabinet_index ⇒ Object (readonly)
Returns the value of attribute cabinet_index.
8 9 10 |
# File 'lib/cabriolet/cab/compressor.rb', line 8 def cabinet_index @cabinet_index end |
#compression ⇒ Object (readonly)
Returns the value of attribute compression.
8 9 10 |
# File 'lib/cabriolet/cab/compressor.rb', line 8 def compression @compression end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/cabriolet/cab/compressor.rb', line 8 def files @files end |
#io_system ⇒ Object (readonly)
Returns the value of attribute io_system.
8 9 10 |
# File 'lib/cabriolet/cab/compressor.rb', line 8 def io_system @io_system end |
#set_id ⇒ Object (readonly)
Returns the value of attribute set_id.
8 9 10 |
# File 'lib/cabriolet/cab/compressor.rb', line 8 def set_id @set_id end |
Instance Method Details
#add_file(source_path, cab_path = nil) ⇒ void
This method returns an undefined value.
Add a file to the cabinet
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cabriolet/cab/compressor.rb', line 26 def add_file(source_path, cab_path = nil) unless ::File.exist?(source_path) raise ArgumentError, "File does not exist: #{source_path}" end unless ::File.file?(source_path) raise ArgumentError, "Not a file: #{source_path}" end @files << { source: source_path, cab_path: cab_path || ::File.basename(source_path), } end |
#generate(output_file, **options) ⇒ Integer
Generate the cabinet file
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cabriolet/cab/compressor.rb', line 50 def generate(output_file, **) raise ArgumentError, "No files to compress" if @files.empty? @compression = [:compression] || @compression @set_id = [:set_id] || @set_id @cabinet_index = [:cabinet_index] || @cabinet_index # Collect file information file_infos = collect_file_infos # Calculate offsets and sizes offsets = calculate_offsets(file_infos) # Compress files and collect data blocks compressed_data = compress_files(file_infos) # Write cabinet file write_cabinet(output_file, file_infos, offsets, compressed_data) end |