Method: CHD::CD.read_toc

Defined in:
lib/chd/cd.rb

.read_toc(chd) ⇒ Array<Hash{Symbol => Object}>?

Read the TOC, and returns it’s information in a parsed form.

Parameters:

  • chd (CHD)

    a chd opened file

Returns:

  • (Array<Hash{Symbol => Object}>)

    Table of Content

  • (nil)

    if the CHD file is not of a CD-ROM / GD-ROM type



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/chd/cd.rb', line 59

def self.read_toc(chd)
    return nil if chd.hunk_bytes %  FRAME_SIZE != 0 ||
                  chd.unit_bytes != FRAME_SIZE
    
    flags  = Set.new
    tracks = []
    while (idx = tracks.size) < MAX_TRACKS do
 if    md = chd.(idx, ::CDROM_TRACK,      )
 elsif md = chd.(idx, ::CDROM_TRACK_PREGAP)
 elsif md = chd.(idx, ::GDROM_OLD,        )
            raise NotSupported, "upgrade your CHD to a more recent version"
 elsif md = chd.(idx, ::GDROM_TRACK,      )
            flags << :GDROM
 else
     break            
 end
        tracks << .parse(*md)
    end
    
    if ! tracks.empty?
        unless tracks.each_with_index.all? {|trackinfo, index|
                   trackinfo[:track] == index + 1
               }
            raise ParsingError, "unordered tracks"
        end
        [ tracks, flags ]
    elsif chd.(0, ::CDROM_OLD)
        raise NotSupported, "upgrade your CHD to a more recent version"
    else
        raise NotFoundError, "provided CHD is not a CD-ROM"
    end
end