Module: Wordlist::Compression::Writer
- Defined in:
- lib/wordlist/compression/writer.rb
Overview
Handles writing compressed files.
Class Method Summary collapse
-
.command(path, format:, append: false) ⇒ String
Returns the command to write to the compressed wordlist.
-
.open(path, **kwargs) ⇒ IO
Opens the compressed wordlist for reading.
Class Method Details
.command(path, format:, append: false) ⇒ String
Returns the command to write to the compressed wordlist.
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.
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 |