Class: ChupaText::Decomposers::Zip

Inherits:
ChupaText::Decomposer show all
Includes:
Loggable, Unzippable
Defined in:
lib/chupa-text/decomposers/zip.rb

Instance Method Summary collapse

Methods inherited from ChupaText::Decomposer

#initialize, registry, #target_score

Constructor Details

This class inherits a constructor from ChupaText::Decomposer

Instance Method Details

#decompose(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/chupa-text/decomposers/zip.rb', line 34

def decompose(data)
  unzip(data) do |zip|
    zip.each do |entry|
      next unless entry.file?

      case entry.encryption_codec
      when Archive::Zip::Codec::NullEncryption
      else
        # TODO
        # entry.password = ...
        raise EncryptedError.new(data)
      end
      entry_uri = data.uri.dup
      base_path = entry_uri.path.gsub(/\.zip\z/i, "")
      path_converter = PathConverter.new(entry.zip_path,
                                         encoding: base_path.encoding,
                                         uri_escape: true)
      entry_uri.path = "#{base_path}/#{path_converter.convert}"
      entry_data = VirtualFileData.new(entry_uri,
                                       entry.file_data,
                                       source_data: data)
      yield(entry_data)
    end
  end
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/chupa-text/decomposers/zip.rb', line 27

def target?(data)
  return true if data.extension == "zip"
  return true if data.mime_type == "application/zip"

  false
end