Method: Zip::Entry#extract

Defined in:
lib/zip/entry.rb

#extract(entry_path = @name, destination_directory: '.', &block) ⇒ Object

Extracts this entry to a file at entry_path, with destination_directory as the base location in the filesystem.

NB: The caller is responsible for making sure destination_directory is safe, if it is passed.



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/zip/entry.rb', line 289

def extract(entry_path = @name, destination_directory: '.', &block)
  dest_dir = ::File.absolute_path(destination_directory || '.')
  extract_path = ::File.absolute_path(::File.join(dest_dir, entry_path))

  unless extract_path.start_with?(dest_dir)
    warn "WARNING: skipped extracting '#{@name}' to '#{extract_path}' as unsafe."
    return self
  end

  block ||= proc { ::Zip.on_exists_proc }

  raise "unknown file type #{inspect}" unless directory? || file? || symlink?

  __send__(:"create_#{ftype}", extract_path, &block)
  self
end