Class: Glark::ArchiveFile
- Inherits:
-
Object
- Object
- Glark::ArchiveFile
- Defined in:
- lib/glark/io/file/archive_file.rb
Instance Method Summary collapse
- #each(&blk) ⇒ Object
-
#initialize(fname, range) ⇒ ArchiveFile
constructor
A new instance of ArchiveFile.
- #list ⇒ Object
- #read(entry) ⇒ Object
- #search(expr, output_type_cls, output_opts) ⇒ Object
- #search_archive_file(expr, entry, output_type_cls, output_opts) ⇒ Object
- #search_list(expr, output_cls, output_opts) ⇒ Object
Constructor Details
#initialize(fname, range) ⇒ ArchiveFile
Returns a new instance of ArchiveFile.
8 9 10 11 |
# File 'lib/glark/io/file/archive_file.rb', line 8 def initialize fname, range @fname = fname @range = range end |
Instance Method Details
#each(&blk) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/glark/io/file/archive_file.rb', line 30 def each &blk reader = get_reader reader.each do |entry| blk.call entry end reader.close end |
#list ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/glark/io/file/archive_file.rb', line 22 def list contents = Array.new each do |entry| contents << entry_name(entry) end contents end |
#read(entry) ⇒ Object
48 49 50 |
# File 'lib/glark/io/file/archive_file.rb', line 48 def read entry entry.read end |
#search(expr, output_type_cls, output_opts) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/glark/io/file/archive_file.rb', line 52 def search expr, output_type_cls, output_opts matched = nil each do |entry| # a glitch with zlib doesn't seem to recognize some tarball entries # (with entry.header.typeflag == "") as being a file, so we test for # directory: next if entry.directory? matched = search_archive_file(expr, entry, output_type_cls, output_opts) || matched end matched end |
#search_archive_file(expr, entry, output_type_cls, output_opts) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/glark/io/file/archive_file.rb', line 38 def search_archive_file expr, entry, output_type_cls, output_opts name = entry_name entry data = read entry contents = StringIO.new data file = Glark::File.new name + " (in #{@fname})", contents, @range output = output_type_cls.new file, output_opts file.search expr, output end |
#search_list(expr, output_cls, output_opts) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/glark/io/file/archive_file.rb', line 13 def search_list expr, output_cls, output_opts contents = StringIO.new list.collect { |x| x + "\n" }.join('') contents.rewind file = Glark::File.new @fname, contents, @range output_type = output_cls.new file, output_opts file.search expr, output_type end |