Module: Wordlist::Compression::Writer

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

Overview

Handles writing compressed files.

Since:

  • 1.0.0

Class Method Summary collapse

Class Method Details

.command(path, format:, append: false) ⇒ String

Returns the command to write to the compressed wordlist.

Parameters:

  • path (String)

    The path to the file.

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

    The compression format of the file.

  • append (Boolean) (defaults to: false)

    Indicates that new words should be appended to the file instead of overwriting the file.

Returns:

  • (String)

    The shellescaped command string.

Raises:

Since:

  • 1.0.0



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/wordlist/compression/writer.rb', line 35

def self.command(path, format: , append: false)
  case format
  when :gzip, :bzip2, :xz
    command  = format.to_s
    redirect = if append then '>>'
               else           '>'
               end

    "#{command} #{redirect} #{Shellwords.shellescape(path)}"
  when :zip
    if append
      raise(AppendNotSupported,"zip format does not support appending to files within pre-existing archives: #{path.inspect}")
    end

    "zip -q #{Shellwords.shellescape(path)} -"
  when :"7zip"
    if append
      raise(AppendNotSupported,"7zip format does not support appending to files within pre-existing archives: #{path.inspect}")
    end

    "7za a -si #{Shellwords.shellescape(path)} >/dev/null"
  else
    raise(UnknownFormat,"unsupported output format: #{format.inspect}")
  end
end

.open(path, **kwargs) ⇒ 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.

  • (CommandNotFound)

    The gzip, bzip2, xz, or zip command was not found on the system.

Since:

  • 1.0.0



80
81
82
83
84
85
86
87
88
# File 'lib/wordlist/compression/writer.rb', line 80

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

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