Class: Ronin::CLI::Commands::Unarchive Private
- Inherits:
-
FileProcessorCommand
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- FileProcessorCommand
- Ronin::CLI::Commands::Unarchive
- Defined in:
- lib/ronin/cli/commands/unarchive.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Unarchive the file(s).
Usage
ronin unarchive [options] FILE ...
Options
-f, --format tar|zip Explicit archive format
Arguments
FILE ... File(s) to unarchive
Constant Summary collapse
- ARCHIVE_FORMATS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Archive file formats and archive types.
{ '.tar' => :tar, '.zip' => :zip }
Instance Method Summary collapse
-
#format_for(path) ⇒ :tar, ...
private
Returns the format for the given archive path.
-
#open_archive(file) {|archive_reader| ... } ⇒ Object
private
Opens archive for read.
-
#run(*files) ⇒ Object
private
Runs the
unarchive
sub-command.
Methods inherited from FileProcessorCommand
#open_file, #process_file, #process_input
Instance Method Details
#format_for(path) ⇒ :tar, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the format for the given archive path.
92 93 94 95 96 |
# File 'lib/ronin/cli/commands/unarchive.rb', line 92 def format_for(path) .fetch(:format) do ARCHIVE_FORMATS[File.extname(path)] end end |
#open_archive(file) {|archive_reader| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Opens archive for read.
Zip or tar reader object.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the unarchive
sub-command.
66 67 68 69 70 71 72 73 74 |
# 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 |