ClamAV::Client is a client library that can talk to the clam daemon.


Add this line to your application's Gemfile:

gem 'clamav-client', require: 'clamav/client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install clamav-client

Alternatively, you can spawn a pry console right away by just running:

$ rake console


  • Ruby >= 2 (and Ruby >= 2.1 to be able to contribute to the project as it's making use of required keyword arguments)
  • clamd


The ClamAV::Client class is responsible for opening a connection to a remote ClamAV clam daemon.

You will find below the implemented commands.

PING => Boolean

Pings the daemon to check whether it is alive.

client =
=> true

SCAN => Array[Response]

Scans a file or a directory for the existence of a virus.

The absolute path must be given to that command.

client =

=> [#<ClamAV::SuccessResponse:0x007fbf314b9478 @file="/tmp/foo.c">]

=> [#<ClamAV::SuccessResponse:0x007fc30c273298 @file="/tmp/path/foo.c">,
 #<ClamAV::SuccessResponse:0x007fc30c272910 @file="/tmp/path/foo.cpp">]

Custom commands

Custom commands can be given to the client. The contract between the client and the command is thru the call method call. The call method is being passed a Connection object.

Here's a simple example that implements the VERSION command:

# Build the client
client =

# Create the command lambda
version_command = lambda { |conn| conn.send_request("VERSION") }
=> #<Proc:0x007fc0d0c14b28>

# Execute the command
=> "1: ClamAV 0.98.1/18489/Tue Feb 18 16:00:05 2014"


The default values in use are:

  • clamd socket: UNIX Socket, located at /tmp/clamd/socket;
  • New-line terminated commands.

These defaults can be changed by injecting new defaults.

Injecting dependencies


The main object is the Client object. It is responsible for executing the commands. This object can receive a custom connection object.


The connection object is the bridge between the raw socket object and the protocol being used between the client and the daemon.

clamd supports two kinds of delimiters:

  • NULL terminated commands
  • New-line terminated commands

The management of those delimiters is done with the wrapper argument.


The wrapper is responsible for taking the incoming request with the wrap_request method, and parsing the response with the read_response method.


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request