Module: Wordlist::Compression::Reader

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

Overview

Handles reading compressed files.

Since:

  • 1.0.0

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, :zip, :7zip)

    The compression format of the file.

Returns:

  • (String)

    The shellescaped command string.

Raises:

  • (UnknownFormat)

    The given format was not :gzip, :bzip2, :xz, :zip, :7zip.

Since:

  • 1.0.0



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wordlist/compression/reader.rb', line 28

def self.command(path, format: )
  case format
  when :gzip   then "zcat < #{Shellwords.shellescape(path)}"
  when :bzip2  then "bzcat < #{Shellwords.shellescape(path)}"
  when :xz     then "xzcat < #{Shellwords.shellescape(path)}"
  when :zip    then "unzip -p #{Shellwords.shellescape(path)}"
  when :"7zip" then "7za e -so #{Shellwords.shellescape(path)}"
  else
    raise(UnknownFormat,"unsupported input format: #{format.inspect}")
  end
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, :xz, :zip, or :7zip.

  • (CommandNotFound)

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

Since:

  • 1.0.0



58
59
60
61
62
63
64
65
66
# File 'lib/wordlist/compression/reader.rb', line 58

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