class ZSteg::FileCmd

Constants

IGNORES
MIN_DATA_SIZE

Public Instance Methods

check_data(data) click to toggle source
# File lib/zsteg/file_cmd.rb, line 76
def check_data data
  @tempfile ||= Tempfile.new('zsteg', :encoding => 'binary')
  @tempfile.rewind
  @tempfile.write data
  @tempfile.flush
  check_file @tempfile.path
end
check_file(fname) click to toggle source
# File lib/zsteg/file_cmd.rb, line 70
def check_file fname
  @stdin.puts fname
  r = @stdout.gets.force_encoding('binary').strip
  IGNORES.any?{ |x| r.index(x) == 0 } ? nil : r
end
data2result(data) click to toggle source

checks data and resurns Result, if any

# File lib/zsteg/file_cmd.rb, line 85
def data2result data
  return if data.size < MIN_DATA_SIZE

  title = check_data data
  return unless title

  if title[/UTF-8 Unicode text/i]
    begin
      t = data.force_encoding("UTF-8")
    rescue
      t = data.force_encoding('binary')
    end
    if t.size >= Checker::DEFAULT_MIN_STR_LEN
      ZSteg::Result::UnicodeText.new(t,0)
    end
  else
    Result.new(title,data)
  end
end
start!() click to toggle source
# File lib/zsteg/file_cmd.rb, line 66
def start!
  @stdin, @stdout, @stderr, @wait_thr = Open3.popen3("file -n -b -f -")
end
stop!() click to toggle source
# File lib/zsteg/file_cmd.rb, line 105
def stop!
  @stdin.close
  @stdout.close
  @stderr.close
ensure
  if @tempfile
    @tempfile.close
    @tempfile.unlink
    @tempfile = nil
  end
end