Module: Wordlist::Compression::Writer
- Defined in:
- lib/wordlist/compression/writer.rb
Overview
Handles writing compressed files.
Constant Summary collapse
- COMMANDS =
Mapping of compression formats to the commands to write to them.
{ gzip: 'gzip', bzip2: 'bzip2', xz: 'xz' }
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.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wordlist/compression/writer.rb', line 39 def self.command(path, format: , append: false) command = COMMANDS.fetch(format) do raise(UnknownFormat,"unsupported format: #{format.inspect}") end redirect = if append then '>>' else '>' end return "#{Shellwords.shellescape(command)} #{redirect} #{Shellwords.shellescape(path)}" end |
.open(path, **kwargs) ⇒ IO
Opens the compressed wordlist for reading.
69 70 71 72 73 74 75 76 77 |
# File 'lib/wordlist/compression/writer.rb', line 69 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 |