module Ronin::Support::Archive

Methods for reading or writing archive files.

## Core-Ext Methods

@api public

@since 1.0.0

Public Class Methods

tar(path,&block) click to toggle source

Opens the tar file for writing.

@param [String] path

The path to the file to write to.

@yield [tar]

If a block is given, it will be passed the tar writer object.

@yieldparam [Tar::Writer] tar

The tar writer object.

@return [Tar::Writer]

The tar writer object.

@see tar_open

@api public

# File lib/ronin/support/archive.rb, line 140
def self.tar(path,&block)
  tar_open(path, mode: 'w', &block)
end
tar_open(path, mode: 'r', &block) click to toggle source

Opens a tar file for reading or writing.

@param [String] path

The path to the tar file.

@param [String] mode

The mode to open the file as.

@yield [tar]

If a block is given, it will be passed the tar writer object.

@yieldparam [Tar::Writer] tar

The tar writer object.

@return [Tar::Writer]

The tar writer object.

@raise [ArgumentError]

The mode must include either `r`, `w`, or `a`.

@see Tar.open

@api public

# File lib/ronin/support/archive.rb, line 94
def self.tar_open(path, mode: 'r', &block)
  Tar.open(path, mode: mode, &block)
end
tar_stream(io, mode: 'r', &block) click to toggle source

Creates a tar stream around the IO object.

@param [IO, StringIO] io

The IO object to read or write data to.

@param [String] mode

The mode to open the tar stream with.

@yield [tar]

If a block is given, it will be passed the tar stream object.

@yieldparam [Tar::Reader, Tar::Writer] tar

The tar reader or writer object.

@return [Tar::Reader, Tar::Writer]

The tar reader or writer object.

@raise [ArgumentError]

The mode must include either `r`, `w`, or `a`.

@see Tar.new

@api public

# File lib/ronin/support/archive.rb, line 65
def self.tar_stream(io, mode: 'r', &block)
  Tar.new(io, mode: mode, &block)
end
untar(path,&block) click to toggle source

Opens the tarped file for reading.

@param [String] path

The path to the file to read.

@yield [tar]

If a block is given, it will be passed the tar reader object.

@yieldparam [Tar::Reader] tar

The tar reader object.

@return [Tar::Reader]

The tar reader object.

@see tar_open

@api public

# File lib/ronin/support/archive.rb, line 117
def self.untar(path,&block)
  tar_open(path,&block)
end
unzip(path,&block) click to toggle source

Opens the zipped file for reading.

@param [String] path

The path to the file to read.

@yield [zip]

If a block is given, it will be passed the zip reader object.

@yieldparam [Zip::Reader] zip

The zip reader object.

@return [Zip::Reader]

The zip reader object.

@see zip_open

@api public

# File lib/ronin/support/archive.rb, line 192
def self.unzip(path,&block)
  zip_open(path,&block)
end
zip(path,&block) click to toggle source

Opens the zip file for writing.

@param [String] path

The path to the file to write to.

@yield [zip]

If a block is given, it will be passed the zip writer object.

@yieldparam [Zip::Writer] zip

The zip writer object.

@return [Zip::Writer]

The zip writer object.

@see zip_open

@api public

# File lib/ronin/support/archive.rb, line 215
def self.zip(path,&block)
  zip_open(path, mode: 'w', &block)
end
zip_open(path, mode: 'r', &block) click to toggle source

Opens a zip file for reading or writing.

@param [String] path

The path to the zip file.

@param [String] mode

The mode to open the file as.

@yield [zip]

If a block is given, it will be passed the zip writer object.

@yieldparam [Zip::Writer] zip

The zip writer object.

@return [Zip::Writer]

The zip writer object.

@raise [ArgumentError]

The mode must include either `r`, `w`, or `a`.

@see Zip.open

@api public

# File lib/ronin/support/archive.rb, line 169
def self.zip_open(path, mode: 'r', &block)
  Zip.open(path, mode: mode, &block)
end