Module: Ronin::Support::Compression::Gzip

Defined in:
lib/ronin/support/compression/gzip.rb,
lib/ronin/support/compression/gzip/reader.rb,
lib/ronin/support/compression/gzip/writer.rb

Overview

Handles gzip compression/decompression.

Since:

  • 1.0.0

Defined Under Namespace

Classes: Reader, Writer

Class Method Summary collapse

Class Method Details

.new(io, mode: 'r') {|gz| ... } ⇒ Reader, Writer

Creates a gzip stream around the IO object.

Parameters:

  • io (IO, StringIO, String)

    The IO or buffer object to read or write data to.

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

    The mode to open the gzip stream in.

Yields:

  • (gz)

    If a block is given, it will be passed the gzip 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/compression/gzip.rb', line 56

def self.new(io, mode: 'r', &block)
  gzip_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 gzip_class.wrap(io,&block)
end

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

Opens a gzip file for reading or writing.

Parameters:

  • path (String)

    The path to the gzip file.

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

    The mode to open the file as.

Yields:

  • (gz)

    If a block is given, it will be passed the gzip 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/compression/gzip.rb', line 91

def self.open(path, mode: 'r', &block)
  gzip_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 gzip_class.open(path,&block)
end