class Ronin::CLI::Commands::Unarchive
Unarchive
the file(s).
## Usage
ronin unarchive [options] FILE ... Options -f, --format tar|zip Explicit archive format
## Arguments
FILE ... File(s) to unarchive
@since 2.1.0
Constants
- ARCHIVE_FORMATS
Archive
file formats and archive types.
Public Instance Methods
format_for(path)
click to toggle source
Returns the format for the given archive path.
@param [String] path
The path to the archive file.
@return [:tar, :zip, nil]
The archive format. `nil` is returned if the format cannot be guessed and the `--format` option was not given.
# File lib/ronin/cli/commands/unarchive.rb, line 92 def format_for(path) options.fetch(:format) do ARCHIVE_FORMATS[File.extname(path)] end end
open_archive(file,&block)
click to toggle source
Opens archive for read.
@param [String] file
File to open.
@yield [archive_reader]
Yielded archived file.
@yieldparam [Ronin::Support::Archive::Zip::Reader,
Ronin::Support::Archive::Tar::Reader] archive_reader Zip or tar reader object.
# File lib/ronin/cli/commands/unarchive.rb, line 111 def open_archive(file,&block) format = format_for(file) case format when :tar Support::Archive.untar(file,&block) when :zip Support::Archive.unzip(file,&block) when nil print_error("unknown archive format: #{file}") else raise(NotImplementedError,"archive format not supported: #{format.inspect}") end end
run(*files)
click to toggle source
Runs the ‘unarchive` sub-command.
@param [Array<String>] files
File arguments.
# File lib/ronin/cli/commands/unarchive.rb, line 66 def run(*files) files.each do |file| open_archive(file) do |archived_files| archived_files.each do |archived_file| File.binwrite(archived_file.name, archived_file.read) end end end end