Module: Ronin::Support::Compression::Mixin

Included in:
Mixin
Defined in:
lib/ronin/support/compression/mixin.rb

Overview

Provides helper methods for compression algorithms/formats.

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#gunzip(path) {|gz| ... } ⇒ Ronin::Support::Compression::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



151
152
153
# File 'lib/ronin/support/compression/mixin.rb', line 151

def gunzip(path,&block)
  Compression.gunzip(path,&block)
end

#gzip(path) {|gz| ... } ⇒ Ronin::Support::Compression::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



174
175
176
# File 'lib/ronin/support/compression/mixin.rb', line 174

def gzip(path,&block)
  Compression.gzip(path,&block)
end

#gzip_open(path, mode: 'r') {|gz| ... } ⇒ Ronin::Support::Compression::Gzip::Reader, Ronin::Support::Compression::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:

  • (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.

See Also:

Since:

  • 1.0.0



128
129
130
# File 'lib/ronin/support/compression/mixin.rb', line 128

def gzip_open(path, mode: 'r', &block)
  Compression.gzip_open(path,mode: mode,&block)
end

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

Creates a gzip stream around the IO object.

Parameters:

  • io (IO, Tempfile, StringIO, String)

    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 IO object must be either an IO, Tempfile, StringIO, or String object. The mode must include either r, w, or a.

See Also:

Since:

  • 1.0.0



98
99
100
# File 'lib/ronin/support/compression/mixin.rb', line 98

def gzip_stream(io, mode: 'r', &block)
  Compression.gzip_stream(io,mode: mode,&block)
end

#zlib_deflate(string) ⇒ String

Zlib deflate a string.

Examples:

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



66
67
68
# File 'lib/ronin/support/compression/mixin.rb', line 66

def zlib_deflate(string)
  Compression.zlib_deflate(string)
end

#zlib_inflate(string) ⇒ String

Zlib inflate a string.

Examples:

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



47
48
49
# File 'lib/ronin/support/compression/mixin.rb', line 47

def zlib_inflate(string)
  Compression.zlib_inflate(string)
end