Class: ChupaText::Decomposers::Gzip

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

Constant Summary collapse

TARGET_EXTENSIONS =
["gz", "tgz"]
TARGET_MIME_TYPES =
[
  "application/gzip",
  "application/x-gzip",
  "application/x-gtar-compressed",
]

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) {|extracted| ... } ⇒ Object

Yields:

  • (extracted)


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chupa-text/decomposers/gzip.rb', line 36

def decompose(data)
  reader = Zlib::GzipReader.new(StringIO.new(data.body))
  uri = nil
  case data.extension
  when "gz"
    uri = data.uri.to_s.gsub(/\.gz\z/i, "")
  when "tgz"
    uri = data.uri.to_s.gsub(/\.tgz\z/i, ".tar")
  end
  extracted = VirtualFileData.new(uri, reader, :source_data => data)
  yield(extracted)
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/chupa-text/decomposers/gzip.rb', line 31

def target?(data)
  TARGET_EXTENSIONS.include?(data.extension) or
    TARGET_MIME_TYPES.include?(data.mime_type)
end