Last active
February 12, 2022 14:38
-
-
Save NikhilNanjappa/7fcba859ba1e1420483120f1a5e48e5e to your computer and use it in GitHub Desktop.
Clam AV scan-file.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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