Class: Ronin::CLI::Commands::Archive Private

Inherits:
FileProcessorCommand show all
Defined in:
lib/ronin/cli/commands/archive.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.

Archive the files.

Usage

ronin archive [option] [FILE ...]

Options

-f, --format tar|zip             Archive format
-o, --output PATH                Archived file path

Arguments

FILE ...                         Optional file(s) to archive

Since:

  • 2.1.0

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.

Mapping of archive file extensions and their formats.

Since:

  • 2.1.0

{
  '.tar' => :tar,
  '.zip' => :zip
}

Instance Method Summary collapse

Methods inherited from FileProcessorCommand

#open_file, #process_file, #process_input

Instance Method Details

#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 archive sub-command.

Parameters:

  • files (Array<String>)

    File arguments.

Since:

  • 2.1.0



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ronin/cli/commands/archive.rb', line 76

def run(*files)
  unless (output = options[:output])
    print_error "must specify the --output option"
    exit(-1)
  end

  format = options.fetch(:format) do
             ARCHIVE_FORMATS.fetch(File.extname(output)) do
               print_error "must either specify --format or a .tar or .zip output file"
               exit(1)
             end
           end

  unless files.empty?
    Ronin::Support::Archive.send(format,output) do |archive|
      files.each do |file|
        archive.add_file(file) do |io|
          File.open(file, 'rb') do |opened_file|
            io.write(opened_file.readpartial(4096)) until opened_file.eof?
          end
        end
      end
    end
  end
end