module Ronin::Support::Compression

Methods for compressing and uncompressing data.

## Core-Ext Methods

@api public

@since 1.0.0

Public Class Methods

gunzip(path,&block) click to toggle source

Opens the gzipped file for reading.

@param [String] path

The path to the file to read.

@yield [gz]

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

@yieldparam [Gzip::Reader] gz

The gzip reader object.

@return [Gzip::Reader]

The gzip reader object.

@see gzip_open

@api public

# File lib/ronin/support/compression.rb, line 157
def self.gunzip(path,&block)
  gzip_open(path,&block)
end
gzip(path,&block) click to toggle source

Opens the gzip file for writing.

@param [String] path

The path to the file to write to.

@yield [gz]

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

@yieldparam [Gzip::Writer] gz

The gzip writer object.

@return [Gzip::Writer]

The gzip writer object.

@see gzip_open

@api public

# 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', &block) click to toggle source

Opens a gzip file for reading or writing.

@param [String] path

The path to the gzip file.

@param [String] mode

The mode to open the file as.

@yield [output]

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

@yieldparam [Gzip::Writer] output

The gzip writer object.

@return [Gzip::Writer]

The gzip writer object.

@raise [ArgumentError]

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

@see Gzip.open

@api public

# 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', &block) click to toggle source

Creates a gzip 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 gzip stream in.

@yield [gz]

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

@yieldparam [Gzip::Reader, Gzip::Writer] gz

The gzip reader or writer object.

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

The gzip reader or writer object.

@raise [ArgumentError]

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

@see Gzip.new

@api public

# 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) click to toggle source

Zlib deflate a string.

@param [String] string

The uncompressed input.

@return [String]

The Zlib deflated form of the input.

@example

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

@api public

# File lib/ronin/support/compression.rb, line 76
def self.zlib_deflate(string)
  Zlib.deflate(string)
end
zlib_inflate(string) click to toggle source

Zlib inflate a string.

@param [String] string

The Zlib compressed input.

@return [String]

The Zlib inflated form of the input.

@example

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

@api public

# File lib/ronin/support/compression.rb, line 57
def self.zlib_inflate(string)
  Zlib.inflate(string)
end