Module: Ronin::Support::Archive::Zip

Defined in:
lib/ronin/support/archive/zip.rb,
lib/ronin/support/archive/zip/reader.rb,
lib/ronin/support/archive/zip/writer.rb,
lib/ronin/support/archive/zip/reader/entry.rb,
lib/ronin/support/archive/zip/reader/statistics.rb

Overview

Handles zip archive reading/writing.

Since:

  • 1.0.0

Defined Under Namespace

Classes: Reader, Writer

Class Method Summary collapse

Class Method Details

.new(path, mode: 'r') {|zip| ... } ⇒ Reader, Writer

Creates a zip archive reader or writer object.

Parameters:

  • path (String)

    The path of the zip archive.

  • mode (String) (defaults to: 'r')

    The mode to open the zip archive in.

Yields:

  • (zip)

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

Yield Parameters:

Returns:

Raises:

  • (ArgumentError)

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

Since:

  • 1.0.0



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ronin/support/archive/zip.rb', line 56

def self.new(path, mode: 'r', &block)
  zip_class = if mode.include?('w') || mode.include?('a')
                Writer
              elsif mode.include?('r')
                Reader
              else
                raise(ArgumentError,"mode argument must include either 'r', 'w', or 'a': #{mode.inspect}")
              end

  return zip_class.new(path,&block)
end

.open(path, mode: 'r') {|gz| ... } ⇒ Reader, Writer

Opens a zip file for reading or writing.

Parameters:

  • path (String)

    The path to the zip file.

  • mode (String) (defaults to: 'r')

    The mode to open the zip file in.

Yields:

  • (gz)

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

Yield Parameters:

Returns:

Raises:

  • (ArgumentError)

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

Since:

  • 1.0.0



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ronin/support/archive/zip.rb', line 91

def self.open(path, mode: 'r', &block)
  zip_class = if mode.include?('w') || mode.include?('a')
                Writer
              elsif mode.include?('r')
                Reader
              else
                raise(ArgumentError,"mode argument must include either 'r', 'w', or 'a'")
              end

  return zip_class.open(path,&block)
end