Class: WSK::RIFFReader
- Inherits:
-
Object
- Object
- WSK::RIFFReader
- Defined in:
- lib/WSK/RIFFReader.rb
Overview
Class reading RIFF files
Instance Method Summary collapse
-
#initialize(iFile) ⇒ RIFFReader
constructor
Constructor.
-
#setFilePos(iRIFFName) ⇒ Object
Position the file on the data associated to a given RIFF name.
Constructor Details
#initialize(iFile) ⇒ RIFFReader
Constructor
- Parameters
- iFile (IO): File to read
15 16 17 |
# File 'lib/WSK/RIFFReader.rb', line 15 def initialize(iFile) @File = iFile end |
Instance Method Details
#setFilePos(iRIFFName) ⇒ Object
Position the file on the data associated to a given RIFF name
- Parameters
- iRIFFName (String): The RIFF name
- Return
- Exception: An error, or nil in case of success
- Integer: The RIFF chunk size
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/WSK/RIFFReader.rb', line 26 def setFilePos(iRIFFName) rError = nil rSize = nil # Loop through the names until we find ours @File.seek(12) lRIFFName, rSize = @File.read(8).unpack('a4V') lCurrentPos = 20 while (lRIFFName != nil) if (lRIFFName == iRIFFName) # We are positioned correctly lRIFFName = nil log_debug "Found RIFF chunk #{iRIFFName} of size #{rSize}" else log_debug "Skip RIFF chunk #{lRIFFName} of size #{rSize}" # Go to the next chunk @File.seek(lCurrentPos + rSize) lData = @File.read(8) lCurrentPos += rSize + 8 if (lData == nil) # End of the file rError = RuntimeError.new("End of file met: no RIFF #{iRIFFName} chunk found.") lRIFFName = nil else lRIFFName, rSize = lData.unpack('a4V') end end end return rError, rSize end |