Class: Omnizip::Formats::Iso::Writer
- Inherits:
-
Object
- Object
- Omnizip::Formats::Iso::Writer
- Defined in:
- lib/omnizip/formats/iso/writer.rb
Overview
ISO 9660 image writer
Creates ISO 9660 filesystem images (CD/DVD images) from files and directories. Supports ISO 9660 levels 1-3, Rock Ridge, and Joliet extensions.
Instance Attribute Summary collapse
-
#application ⇒ String
Application identifier.
-
#directories ⇒ Array<Hash>
readonly
Directories to add.
-
#files ⇒ Array<Hash>
readonly
Files to add.
-
#joliet ⇒ Boolean
Use Joliet extensions.
-
#level ⇒ Integer
ISO 9660 level (1, 2, or 3).
-
#options ⇒ Hash
readonly
Writer options.
-
#output_path ⇒ String
readonly
Output ISO file path.
-
#preparer ⇒ String
Preparer.
-
#publisher ⇒ String
Publisher.
-
#rock_ridge ⇒ Boolean
Use Rock Ridge extensions.
-
#system_id ⇒ String
System identifier.
-
#volume_id ⇒ String
Volume identifier (label).
Instance Method Summary collapse
-
#add_directory(dir_path, recursive: true, iso_path: nil) ⇒ Object
Add directory to ISO image.
-
#add_file(file_path, iso_path = nil) ⇒ Object
Add file to ISO image.
-
#initialize(output_path, options = {}) ⇒ Writer
constructor
Initialize ISO writer.
-
#write ⇒ Object
Create ISO image.
Constructor Details
#initialize(output_path, options = {}) ⇒ Writer
Initialize ISO writer
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/omnizip/formats/iso/writer.rb', line 76 def initialize(output_path, = {}) @output_path = output_path @options = .merge() @volume_id = @options[:volume_id] @system_id = @options[:system_id] @publisher = @options[:publisher] @preparer = @options[:preparer] @application = @options[:application] @level = @options[:level] @rock_ridge = @options[:rock_ridge] @joliet = @options[:joliet] @files = [] @directories = [] end |
Instance Attribute Details
#application ⇒ String
Returns Application identifier.
47 48 49 |
# File 'lib/omnizip/formats/iso/writer.rb', line 47 def application @application end |
#directories ⇒ Array<Hash> (readonly)
Returns Directories to add.
62 63 64 |
# File 'lib/omnizip/formats/iso/writer.rb', line 62 def directories @directories end |
#files ⇒ Array<Hash> (readonly)
Returns Files to add.
59 60 61 |
# File 'lib/omnizip/formats/iso/writer.rb', line 59 def files @files end |
#joliet ⇒ Boolean
Returns Use Joliet extensions.
56 57 58 |
# File 'lib/omnizip/formats/iso/writer.rb', line 56 def joliet @joliet end |
#level ⇒ Integer
Returns ISO 9660 level (1, 2, or 3).
50 51 52 |
# File 'lib/omnizip/formats/iso/writer.rb', line 50 def level @level end |
#options ⇒ Hash (readonly)
Returns Writer options.
32 33 34 |
# File 'lib/omnizip/formats/iso/writer.rb', line 32 def @options end |
#output_path ⇒ String (readonly)
Returns Output ISO file path.
29 30 31 |
# File 'lib/omnizip/formats/iso/writer.rb', line 29 def output_path @output_path end |
#preparer ⇒ String
Returns Preparer.
44 45 46 |
# File 'lib/omnizip/formats/iso/writer.rb', line 44 def preparer @preparer end |
#publisher ⇒ String
Returns Publisher.
41 42 43 |
# File 'lib/omnizip/formats/iso/writer.rb', line 41 def publisher @publisher end |
#rock_ridge ⇒ Boolean
Returns Use Rock Ridge extensions.
53 54 55 |
# File 'lib/omnizip/formats/iso/writer.rb', line 53 def rock_ridge @rock_ridge end |
#system_id ⇒ String
Returns System identifier.
38 39 40 |
# File 'lib/omnizip/formats/iso/writer.rb', line 38 def system_id @system_id end |
#volume_id ⇒ String
Returns Volume identifier (label).
35 36 37 |
# File 'lib/omnizip/formats/iso/writer.rb', line 35 def volume_id @volume_id end |
Instance Method Details
#add_directory(dir_path, recursive: true, iso_path: nil) ⇒ Object
Add directory to ISO image
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/omnizip/formats/iso/writer.rb', line 117 def add_directory(dir_path, recursive: true, iso_path: nil) raise ArgumentError, "Directory not found: #{dir_path}" unless Dir.exist?(dir_path) iso_path ||= File.basename(dir_path) iso_path = sanitize_path(iso_path) if recursive add_directory_recursive(dir_path, iso_path) else add_directory_flat(dir_path, iso_path) end end |
#add_file(file_path, iso_path = nil) ⇒ Object
Add file to ISO image
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/omnizip/formats/iso/writer.rb', line 98 def add_file(file_path, iso_path = nil) raise ArgumentError, "File not found: #{file_path}" unless File.exist?(file_path) iso_path ||= File.basename(file_path) @files << { source: File.(file_path), iso_path: sanitize_path(iso_path), stat: File.stat(file_path), } end |
#write ⇒ Object
Create ISO image
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/omnizip/formats/iso/writer.rb', line 134 def write File.open(@output_path, "wb") do |io| # Build directory structure builder = DirectoryBuilder.new( @files, @directories, level: @level, rock_ridge: @rock_ridge, ) dir_structure = builder.build # Build volume descriptor volume_builder = VolumeBuilder.new( volume_id: @volume_id, system_id: @system_id, publisher: @publisher, preparer: @preparer, application: @application, level: @level, rock_ridge: @rock_ridge, joliet: @joliet, ) # Write ISO structure write_system_area(io) write_volume_descriptors(io, volume_builder, dir_structure) write_path_tables(io, dir_structure) write_directories(io, dir_structure) write_file_data(io) end @output_path end |