Skip to content

Instantly share code, notes, and snippets.

@samuelkarani
Last active December 16, 2022 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelkarani/760e63d9d93f4498f9ca52da32bb23e3 to your computer and use it in GitHub Desktop.
Save samuelkarani/760e63d9d93f4498f9ca52da32bb23e3 to your computer and use it in GitHub Desktop.
const NodeClam = require('clamscan');
module.exports = async function scanFile(filePath) {
console.log(`Attempting virus scan for ${filePath}`);
const clamscan = await new NodeClam().init({
remove_infected: true,
debug_mode: false,
scan_recursively: false,
clamdscan: {
socket: process.env.CLAMDSCAN_SOCKET || '/var/run/clamav/clamd.ctl',
timeout: 120000,
local_fallback: true,
path: process.env.CLAMDSCAN_PATH || '/var/lib/clamav',
config_file: process.env.CLAMDSCAN_CONFIG_FILE || '/etc/clamav/clamd.conf'
}
});
const { is_infected, viruses } = await clamscan.scan_file(filePath);
if (is_infected) {
console.error(`Virus scan failed, file INFECTED`, { filePath, viruses });
} else {
console.log(`Virus scan OK`, { filePath });
}
return { is_infected, viruses };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment