Module: Ronin::Support::Compression

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

Overview

Methods for compressing and uncompressing data.

Core-Ext Methods

Since:

  • 1.0.0

Defined Under Namespace

Modules: Gzip, Mixin, Zlib

Class Method Summary collapse

Class Method Details

.gunzip(path) {|gz| ... } ⇒ Gzip::Reader

Opens the gzipped file for reading.

Parameters:

  • path (String)

    The path to the file to read.

Yields:

  • (gz)

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

Yield Parameters:

Returns:

See Also:

Since:

  • 1.0.0



157
158
159
# File 'lib/ronin/support/compression.rb', line 157

def self.gunzip(path,&block)
  gzip_open(path,&block)
end

.gzip(path) {|gz| ... } ⇒ Gzip::Writer

Opens the gzip file for writing.

Parameters:

  • path (String)

    The path to the file to write to.

Yields:

  • (gz)

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

Yield Parameters:

Returns:

See Also:

Since:

  • 1.0.0



180
181
182
# File 'lib/ronin/support/compression.rb', line 180

def self.gzip(path,&block)
  gzip_open(path, mode: 'w', &block)
end

.gzip_open(path, mode: 'r') {|output| ... } ⇒ Gzip::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:

  • (output)

    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.

See Also:

Since:

  • 1.0.0



134
135
136
# File 'lib/ronin/support/compression.rb', line 134

def self.gzip_open(path, mode: 'r', &block)
  Gzip.open(path, mode: mode, &block)
end

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

Creates a gzip stream around the IO object.

Parameters:

  • io (IO, StringIO)

    The IO 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.

See Also:

Since:

  • 1.0.0



105
106
107
# File 'lib/ronin/support/compression.rb', line 105

def self.gzip_stream(io, mode: 'r', &block)
  Gzip.new(io, mode: mode, &block)
end

.zlib_deflate(string) ⇒ String

Zlib deflate a string.

Examples:

Compression.zlib_deflate("hello")
# => "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15"

Parameters:

  • string (String)

    The uncompressed input.

Returns:

  • (String)

    The Zlib deflated form of the input.

Since:

  • 1.0.0



76
77
78
# File 'lib/ronin/support/compression.rb', line 76

def self.zlib_deflate(string)
  Zlib.deflate(string)
end

.zlib_inflate(string) ⇒ String

Zlib inflate a string.

Examples:

Compression.zlib_inflate("x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15")
# => "hello"

Parameters:

  • string (String)

    The Zlib compressed input.

Returns:

  • (String)

    The Zlib inflated form of the input.

Since:

  • 1.0.0



57
58
59
# File 'lib/ronin/support/compression.rb', line 57

def self.zlib_inflate(string)
  Zlib.inflate(string)
end