Perl, ClamAV, scan a stream for viruses

2.2k views Asked by At

I have a perl app. I need to scan some files for viruses .

I can use the ClamAV and the module File::Scan::ClamAV . It works if i need to scan some file stored on disk or if a file is loaded to a memory (to some variable).

But my app doesn't have full file. It only has an input stream (opened socket). It reads from this socket and writes to other output stream.

Can i pass somehow the stream through ClamAV? Like to forward my input stream to clamav and read data back from it but at the end to get some result of scanning?

1

There are 1 answers

3
simbabque On BEST ANSWER

The module ClamAV::Client seems to provide a means to scan streams with the scan_stream method.

Here's how I think that works puzzled together from the documentation:

use ClamAV::Client;

# Try using socket options from clamd.conf, or use default socket:
my $scanner = ClamAV::Client->new();

# Scan a stream, i.e. read from an I/O handle:
my $result = $scanner->scan_stream($handle);

# $result is the name of a virus signature, or undef
die "infected" if $result;

Note that I have not tried it (yet).