Skip to content

Instantly share code, notes, and snippets.

@NikhilNanjappa
Last active February 12, 2022 14:38
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 NikhilNanjappa/7fcba859ba1e1420483120f1a5e48e5e to your computer and use it in GitHub Desktop.
Save NikhilNanjappa/7fcba859ba1e1420483120f1a5e48e5e to your computer and use it in GitHub Desktop.
Clam AV scan-file.js
'use strict';
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