Created
March 29, 2018 10:18
-
-
Save ucnv/4659ba64cf1ffd2074e4dde5ef4541a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rifftree io, depth = 0, len = 0 | |
offset = io.pos | |
while id = io.read(4) do | |
if len > 0 && io.pos >= offset + len | |
io.pos -= 4 | |
break | |
end | |
size = io.read(4).unpack('V').first | |
out = depth > 0 ? ' ' * depth + id : id | |
if id =~ /^(?:RIFF|LIST)$/ | |
lid = io.read(4) | |
out << ' - ' + lid | |
out << ' (%d)' % size | |
puts out | |
rifftree io, depth + 1, size | |
else | |
out << ' (%d)' % size | |
puts out | |
io.pos += size | |
io.pos += 1 if size % 2 == 1 | |
end | |
end | |
end | |
open(ARGV.shift, 'rb') do |io| | |
rifftree io | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment