Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created March 29, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucnv/4659ba64cf1ffd2074e4dde5ef4541a0 to your computer and use it in GitHub Desktop.
Save ucnv/4659ba64cf1ffd2074e4dde5ef4541a0 to your computer and use it in GitHub Desktop.
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