Module: Wordlist::Compression::Reader

Defined in:
lib/wordlist/compression/reader.rb

Overview

Handles reading compressed files.

Since:

  • 1.0.0

Constant Summary collapse

COMMANDS =

Mapping of compression formats to the commands to read them.

Since:

  • 1.0.0

{
  gzip:  'zcat',
  bzip2: 'bzcat',
  xz:    'xzcat'
}

Class Method Summary collapse

Class Method Details

.command(path, format:) ⇒ String

Returns the command to read the compressed wordlist.

Parameters:

  • path (String)

    The path to the file.

  • format (:gzip, :bzip2, :xz)

    The compression format of the file.

Returns:

  • (String)

    The shellescaped command string.

Raises:

  • (UnknownFormat)

    The given format was not :gzip, :bzip2, or :xz.

Since:

  • 1.0.0



35
36
37
38
39
40
41
# File 'lib/wordlist/compression/reader.rb', line 35

def self.command(path, format: )
  command = COMMANDS.fetch(format) do
    raise(UnknownFormat,"unsupported format: #{format.inspect}")
  end

  "#{command} < #{Shellwords.shellescape(path)}"
end

.open(path, **kwargs, &block) ⇒ IO

Opens the compressed wordlist for reading.

Parameters:

  • path (String)

    The path to the file.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for command.

Returns:

  • (IO)

    The uncompressed IO stream.

Raises:

  • (ArgumentError)

    The given format was not :gzip, :bzip2, or :xz.

  • (CommandNotFound)

    The zcat, bzcat, or xzcat command could not be found.

Since:

  • 1.0.0



61
62
63
64
65
66
67
68
69
# File 'lib/wordlist/compression/reader.rb', line 61

def self.open(path,**kwargs,&block)
  command = self.command(path,**kwargs)

  begin
    IO.popen(command,&block)
  rescue Errno::ENOENT
    raise(CommandNotFound,"#{command.inspect} command not found")
  end
end