Created
July 10, 2013 08:25
-
-
Save bnagy/5964435 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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