Class: Railsmdb::TarGzipExtractor Private

Inherits:
Extractor
  • Object
show all
Defined in:
lib/railsmdb/extractor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An extractor subclass for dealing with .tgz/.tar.gz files.

Instance Attribute Summary

Attributes inherited from Extractor

#archive_path

Instance Method Summary collapse

Methods inherited from Extractor

for, #initialize

Constructor Details

This class inherits a constructor from Railsmdb::Extractor

Instance Method Details

#extract(pattern) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Extractor#extract for documentation.



74
75
76
77
78
79
80
81
82
83
# File 'lib/railsmdb/extractor.rb', line 74

def extract(pattern)
  reader.each_entry do |entry|
    if entry.name.match?(pattern)
      yield entry.name, entry.read.force_encoding('BINARY')
      return entry.name
    end
  end

  nil
end

#readerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a reader able to iterate over all the entries in the archive.



87
88
89
90
91
92
# File 'lib/railsmdb/extractor.rb', line 87

def reader
  @reader ||= begin
    gzip = Zlib::GzipReader.new(File.open(archive_path, 'rb'))
    Minitar::Reader.new(gzip)
  end
end