Class: SafeZip::Extract

Inherits:
Object
  • Object
show all
Defined in:
lib/safe_zip/extract.rb

Overview

SafeZip::Extract provides a safe interface to extract specific directories or files within a ‘zip` archive.

Examples:

Extract directories to destination

SafeZip::Extract.new(archive_file).extract(directories: ['app/', 'test/'], to: destination_path)

Extract files to destination

SafeZip::Extract.new(archive_file).extract(files: ['index.html', 'app/index.js'], to: destination_path)

Constant Summary collapse

Error =
Class.new(StandardError)
PermissionDeniedError =
Class.new(Error)
SymlinkSourceDoesNotExistError =
Class.new(Error)
UnsupportedEntryError =
Class.new(Error)
EntrySizeError =
Class.new(Error)
AlreadyExistsError =
Class.new(Error)
NoMatchingError =
Class.new(Error)
ExtractError =
Class.new(Error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive_file) ⇒ Extract

Returns a new instance of Extract.



23
24
25
# File 'lib/safe_zip/extract.rb', line 23

def initialize(archive_file)
  @archive_path = archive_file
end

Instance Attribute Details

#archive_pathObject (readonly)

Returns the value of attribute archive_path.



21
22
23
# File 'lib/safe_zip/extract.rb', line 21

def archive_path
  @archive_path
end

Instance Method Details

#extract(opts = {}) ⇒ Object

extract given files or directories from the archive into the destination path

Parameters:

  • opts (Hash) (defaults to: {})

    the options for extraction.

Options Hash (opts):

  • Array (Array<String] :files list of files to be extracted)

    :files list of files to be extracted

  • Array (Array<String] :directories list of directories to be extracted)

    :directories list of directories to be extracted

  • :to (String)

    destination path

Raises:



41
42
43
44
45
# File 'lib/safe_zip/extract.rb', line 41

def extract(opts = {})
  params = SafeZip::ExtractParams.new(**opts)

  extract_with_ruby_zip(params)
end