Class: Inspec::ZipProvider
- Inherits:
- 
      FileProvider
      
        - Object
- FileProvider
- Inspec::ZipProvider
 
- Defined in:
- lib/inspec/file_provider.rb
Overview
class DirProvider
Instance Attribute Summary collapse
- 
  
    
      #files  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute files. 
Instance Method Summary collapse
- #extract(destination_path = ".") ⇒ Object
- 
  
    
      #initialize(path)  ⇒ ZipProvider 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of ZipProvider. 
- #read(file) ⇒ Object
Methods inherited from FileProvider
#binread, for_path, #relative_provider
Constructor Details
#initialize(path) ⇒ ZipProvider
Returns a new instance of ZipProvider.
| 97 98 99 100 101 102 103 104 105 106 107 | # File 'lib/inspec/file_provider.rb', line 97 def initialize(path) @path = path @contents = {} @files = [] walk_zip(@path) do |io| while (entry = io.get_next_entry) name = entry.name.sub(%r{/+$}, "") @files.push(name) unless name.empty? || name.squeeze("/") =~ %r{\.{2}(?:/|\z)} end end end | 
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
| 95 96 97 | # File 'lib/inspec/file_provider.rb', line 95 def files @files end | 
Instance Method Details
#extract(destination_path = ".") ⇒ Object
| 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | # File 'lib/inspec/file_provider.rb', line 109 def extract(destination_path = ".") FileUtils.mkdir_p(destination_path) Zip::File.open(@path) do |archive| archive.each do |file| final_path = File.join(destination_path, file.name) # This removes the top level directory (and any other files) to ensure # extracted files do not conflict. FileUtils.remove_entry(final_path) if File.exist?(final_path) archive.extract(file, final_path) end end end | 
#read(file) ⇒ Object
| 125 126 127 | # File 'lib/inspec/file_provider.rb', line 125 def read(file) @contents[file] ||= read_from_zip(file) end |