class ChupaText::Decomposers::Gzip
Constants
- TARGET_EXTENSIONS
- TARGET_MIME_TYPES
Public Instance Methods
Source
# File lib/chupa-text/decomposers/gzip.rb, line 37 def decompose(data) open_reader(data) do |reader| 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 end
Source
# File lib/chupa-text/decomposers/gzip.rb, line 32 def target?(data) TARGET_EXTENSIONS.include?(data.extension) or TARGET_MIME_TYPES.include?(data.mime_type) end
Private Instance Methods
Source
# File lib/chupa-text/decomposers/gzip.rb, line 67 def log_tag "[decomposer][gzip]" end
Source
# File lib/chupa-text/decomposers/gzip.rb, line 52 def open_reader(data) data.open do |input| begin yield(Zlib::GzipReader.new(input)) rescue Zlib::Error => zlib_error error do message = "#{log_tag} Failed to uncompress: " message << "#{zlib_error.class}: #{zlib_error.message}\n" message << zlib_error.backtrace.join("\n") message end end end end