class ClamAV::Client

Public Class Methods

new(connection = default_connection) click to toggle source
# File lib/clamav/client.rb, line 28
def initialize(connection = default_connection)
  @connection = connection
  connection.establish_connection
end

Public Instance Methods

default_connection() click to toggle source
# File lib/clamav/client.rb, line 37
def default_connection
  ClamAV::Connection.new(
    socket: resolve_default_socket,
    wrapper: ::ClamAV::Wrappers::NewLineWrapper.new
  )
end
execute(command) click to toggle source
# File lib/clamav/client.rb, line 33
def execute(command)
  command.call(@connection)
end
ping() click to toggle source
# File lib/clamav/client.rb, line 53
def ping
  execute Commands::PingCommand.new
end
resolve_default_socket() click to toggle source
# File lib/clamav/client.rb, line 44
def resolve_default_socket
  unix_socket, tcp_host, tcp_port = ENV.values_at('CLAMD_UNIX_SOCKET', 'CLAMD_TCP_HOST', 'CLAMD_TCP_PORT')
  if tcp_host && tcp_port
    ::TCPSocket.new(tcp_host, tcp_port)
  else
    ::UNIXSocket.new(unix_socket || '/var/run/clamav/clamd.ctl')
  end
end
safe?(target) click to toggle source
# File lib/clamav/client.rb, line 57
def safe?(target)
  return instream(target).virus_name.nil? if target.is_a?(StringIO)
  scan(target).all? { |file| file.virus_name.nil? }
end

Private Instance Methods

instream(io) click to toggle source
# File lib/clamav/client.rb, line 64
def instream(io)
  execute Commands::InstreamCommand.new(io)
end
scan(file_path) click to toggle source
# File lib/clamav/client.rb, line 68
def scan(file_path)
  execute Commands::ScanCommand.new(file_path)
end