Class: HexaPDF::CLI::DebugInfo
- Defined in:
- lib/hexapdf/cli/debug_info.rb
Overview
Creates debugging information for adding to an issue.
Instance Method Summary collapse
-
#execute(file) ⇒ Object
:nodoc:.
-
#initialize ⇒ DebugInfo
constructor
:nodoc:.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ DebugInfo
:nodoc:
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hexapdf/cli/debug_info.rb', line 45 def initialize #:nodoc: super('debug-info', takes_commands: false) short_desc("Create debug information for a PDF file") long_desc(" Creates debug information for a possibly malformed PDF file that can be attached to an\n issue.\n\n Two files are created: anonymized-FILE where all strings are replaced with zeroes and\n debug_info.txt with additional debug information.\n EOF\n\n options.on(\"--password PASSWORD\", \"-p\", String,\n \"The password for decryption. Use - for reading from standard input.\") do |pwd|\n @password = (pwd == '-' ? read_password : pwd)\n end\n\n @password = nil\nend\n") |
Instance Method Details
#execute(file) ⇒ Object
:nodoc:
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hexapdf/cli/debug_info.rb', line 64 def execute(file) #:nodoc: output_name = "anonymized-#{file}" puts "Creating anonymized file '#{output_name}'" data = File.binread(file) data.gsub!(/(>>\s*stream\s*)(.*?)(\s*endstream)/m) {|m| "#{$1}#{'0' * $2.length}#{$3}" } data.gsub!(/([^<]<)([0-9A-Fa-f#{Tokenizer::WHITESPACE}]*?)>/m) {|m| "#{$1}#{'0' * $2.length}>" } data.gsub!(/\((.*?)\)/m) {|m| "(#{'0' * $1.length})" } File.binwrite(output_name, data) debug_info = +'' puts "Collecting debug information in debug_info.txt" begin output = capture_output { HexaPDF::CLI::Application.new.parse(['info', '--check', file]) } debug_info << "Output:\n"<< output rescue debug_info << "Error collecting info: #{$!.message}\n" end File.write('debug_info.txt', debug_info) end |