Module: Omnizip::Formats::Iso

Defined in:
lib/omnizip/formats/iso.rb,
lib/omnizip/formats/iso/joliet.rb,
lib/omnizip/formats/iso/reader.rb,
lib/omnizip/formats/iso/writer.rb,
lib/omnizip/formats/iso/path_table.rb,
lib/omnizip/formats/iso/rock_ridge.rb,
lib/omnizip/formats/iso/volume_builder.rb,
lib/omnizip/formats/iso/directory_record.rb,
lib/omnizip/formats/iso/directory_builder.rb,
lib/omnizip/formats/iso/volume_descriptor.rb

Overview

ISO 9660 CD-ROM filesystem format support Provides read-only access to ISO images

ISO 9660 is the standard filesystem for CD-ROMs and DVD-ROMs. This implementation supports:

  • Primary Volume Descriptor parsing
  • Directory structure traversal
  • File extraction
  • Rock Ridge extensions (basic)

Defined Under Namespace

Modules: Joliet, RockRidge Classes: DirectoryBuilder, DirectoryRecord, PathTable, Reader, VolumeBuilder, VolumeDescriptor, Writer

Constant Summary collapse

SECTOR_SIZE =

ISO 9660 constants

2048
SYSTEM_AREA_SECTORS =
16
VOLUME_DESCRIPTOR_START =
SYSTEM_AREA_SECTORS
VD_BOOT_RECORD =

Volume descriptor types

0
VD_PRIMARY =
1
VD_SUPPLEMENTARY =
2
VD_PARTITION =
3
VD_TERMINATOR =
255
FLAG_HIDDEN =

File flags

0x01
FLAG_DIRECTORY =
0x02
FLAG_ASSOCIATED =
0x04
FLAG_EXTENDED =
0x08
FLAG_PERMISSIONS =
0x10
FLAG_NOT_FINAL =
0x80

Class Method Summary collapse

Class Method Details

.create(path, options = {}) {|writer| ... } ⇒ String

Create ISO 9660 image

Examples:

Create ISO image

Omnizip::Formats::Iso.create('backup.iso') do |iso|
  iso.volume_id = 'BACKUP_2024'
  iso.add_directory('documents/')
end

With Rock Ridge and Joliet

Omnizip::Formats::Iso.create('cdrom.iso',
  rock_ridge: true,
  joliet: true
) do |iso|
  iso.add_directory('files/')
end

Parameters:

  • path (String)

    Output ISO file path

  • options (Hash) (defaults to: {})

    Creation options

Yields:

  • (writer)

    Block for adding files/directories

Yield Parameters:

  • writer (Writer)

    ISO writer

Returns:

  • (String)

    Path to created ISO



123
124
125
126
127
128
129
# File 'lib/omnizip/formats/iso.rb', line 123

def self.create(path, options = {})
  writer = Writer.new(path, options)

  yield writer if block_given?

  writer.write
end

.extract(iso_path, output_dir) ⇒ Object

Extract ISO contents

Parameters:

  • iso_path (String)

    Path to ISO file

  • output_dir (String)

    Output directory



79
80
81
82
83
# File 'lib/omnizip/formats/iso.rb', line 79

def self.extract(iso_path, output_dir)
  open(iso_path) do |iso|
    iso.extract_all(output_dir)
  end
end

.info(path) ⇒ Hash

Get ISO volume information

Parameters:

  • path (String)

    Path to ISO file

Returns:

  • (Hash)

    Volume information



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/omnizip/formats/iso.rb', line 89

def self.info(path)
  open(path) do |iso|
    {
      format: "ISO 9660",
      volume_id: iso.volume_identifier,
      system_id: iso.system_identifier,
      size: iso.volume_size,
      files: iso.entries.count { |e| !e.directory? },
      directories: iso.entries.count(&:directory?),
    }
  end
end

.list(path) ⇒ Array<DirectoryRecord>

List contents of ISO image

Parameters:

  • path (String)

    Path to ISO file

Returns:



71
72
73
# File 'lib/omnizip/formats/iso.rb', line 71

def self.list(path)
  open(path, &:entries)
end

.open(path) {|reader| ... } ⇒ Reader

Open existing ISO image

Parameters:

  • path (String)

    Path to ISO file

Yields:

  • (reader)

    Block for reading archive

Yield Parameters:

  • reader (Reader)

    ISO reader

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/omnizip/formats/iso.rb', line 52

def self.open(path)
  reader = Reader.new(path)
  reader.open

  if block_given?
    begin
      yield reader
    ensure
      reader.close
    end
  end

  reader
end

.register!Object

Auto-register ISO format when loaded



132
133
134
# File 'lib/omnizip/formats/iso.rb', line 132

def self.register!
  FormatRegistry.register(".iso", Reader)
end