Class: Glark::TarGzFile

Inherits:
Object
  • Object
show all
Includes:
Logue::Loggable
Defined in:
lib/glark/io/file/tar_gz_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(fname, range) ⇒ TarGzFile

Returns a new instance of TarGzFile.



13
14
15
16
# File 'lib/glark/io/file/tar_gz_file.rb', line 13

def initialize fname, range
  @fname = fname
  @range = range
end

Instance Method Details

#listObject



18
19
20
21
22
23
24
# File 'lib/glark/io/file/tar_gz_file.rb', line 18

def list
  contents = Array.new
  each_file do |entry|
    contents << entry.full_name
  end
  contents
end

#run_search(&blk) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/glark/io/file/tar_gz_file.rb', line 26

def run_search &blk
  # a glitch with zlib results in a warning ("attempt to close unfinished
  # zstream; reset forced.") for some tarballs, so we turn off warnings for
  # a moment:
  $-w = false
  
  Zlib::GzipReader.open(@fname) do |gzio|
    tarfile = Glark::TarFile.new @fname, @range, gzio
    blk.call tarfile
  end

  $-w = true
end

#search(expr, output_type_cls, output_opts) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/glark/io/file/tar_gz_file.rb', line 46

def search expr, output_type_cls, output_opts
  matched = nil
  run_search do |tarfile|
    matched = tarfile.search(expr, output_type_cls, output_opts) || matched
  end
  matched
end

#search_list(expr, output_cls, output_opts) ⇒ Object



40
41
42
43
44
# File 'lib/glark/io/file/tar_gz_file.rb', line 40

def search_list expr, output_cls, output_opts
  run_search do |tarfile|
    tarfile.search_list expr, output_cls, output_opts
  end
end