Class: ChupaText::Decomposers::Tar

Inherits:
ChupaText::Decomposer show all
Defined in:
lib/chupa-text/decomposers/tar.rb

Defined Under Namespace

Modules: CopyStreamable

Instance Method Summary collapse

Methods inherited from ChupaText::Decomposer

#initialize, registry

Constructor Details

This class inherits a constructor from ChupaText::Decomposer

Instance Method Details

#decompose(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chupa-text/decomposers/tar.rb', line 30

def decompose(data)
  Gem::Package::TarReader.new(StringIO.new(data.body)) do |reader|
    reader.each do |entry|
      next unless entry.file?

      entry.extend(CopyStreamable)
      entry_uri = data.uri.dup
      base_path = entry_uri.path.gsub(/\.tar\z/i, "")
      entry_uri.path = "#{base_path}/#{entry.full_name}"
      extracted = VirtualFileData.new(entry_uri,
                                      entry,
                                      :source_data => data)
      yield(extracted)
    end
  end
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/chupa-text/decomposers/tar.rb', line 25

def target?(data)
  data.extension == "tar" or
    data.mime_type == "application/x-tar"
end