Class: ChupaText::Decomposers::Gzip
Constant Summary
collapse
- TARGET_EXTENSIONS =
["gz", "tgz"]
- TARGET_MIME_TYPES =
[
"application/gzip",
"application/x-gzip",
"application/x-gtar-compressed",
]
Instance Method Summary
collapse
#initialize, registry
Instance Method Details
#decompose(data) {|extracted| ... } ⇒ Object
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
= VirtualFileData.new(uri, reader, :source_data => data)
yield()
end
|
#target?(data) ⇒ 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
|