Ruby: undefined method 'unpack' when I'm trying to extract data between to regex markers in a hex file

1.2k views Asked by At
#!/usr/bin/env ruby
#this is the capture file from tcpdump for printer (9100) traffic
filename = 'cap.pcl'
capdata = {}

File.open(filename,"r") {|capdata| capdata.read}

#this is the regex that identifies the print job type as PCL or PJL
  if capdata.unpack("H*")[0] =~ /(1b45|1b25|1b26)/
    printjobtype = "PCL"
    print_good("Printjob of type PCL recieved")

  #trying to extract only the data between these 2 markers
    print_job_pcl = Array(pcdata.unpack("H*")[0].match(/((1b45|1b25|1b26).*(1b45|1b252d313233343558))/i)[0]).pack("H*")
  end
## error I'm receiving, 
## extractPrintJob.rb:8: undefined method `unpack' for #<File:cap.pcl (closed)> (NoMethodError)
0

There are 0 answers