Skip to content

Instantly share code, notes, and snippets.

@bnagy
Created July 10, 2013 08:25
Show Gist options
  • Save bnagy/5964435 to your computer and use it in GitHub Desktop.
Save bnagy/5964435 to your computer and use it in GitHub Desktop.
class ArcFile
include Enumerable
def initialize( input_stream )
@handle=input_stream
end
def each
return self.to_enum unless block_given?
begin
# See http://www.archive.org/web/researcher/ArcFileFormat.php
# for information about the ARC format once it is decompressed
[email protected]
[email protected]( Integer(main_header.split.last) )
loop do
begin
[email protected]
[email protected]( Integer(record_header.split.last) )
unless ([email protected](1))=="\n"
raise ArgumentError, "#{self.class}: Corrupt ARCfile? Expected \\n as record terminator, got #{byte}"
end
yield [record_header, record_body]
rescue EOFError
break nil
end
end
rescue
raise "#{self.class}: Error processing - #{$!}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment