1

我正在运行一个简单的clamscan 示例。

const NodeClam = require('clamscan');

let options = {
    debug_mode: true,
    // clamdscan: {
    //     socket: '/var/run/clamav/clamd.ctl', // This is pretty typical
    //     host: '127.0.0.1', // If you want to connect locally but not through socket
    //     port: 3310, // Because, why not
    //     timeout: 300000, // 5 minutes
    //     local_fallback: true, // Use local preferred binary to scan if socket/tcp fails
    //     path: '/usr/bin/clamdscan', // Special path to the clamdscan binary on your server
    //     config_file: '/etc/clamav/clamd.conf', // A fairly typical config location
    //     multiscan: false, // You hate speed and multi-threaded awesome-sauce
    //     reload_db: true, // You want your scans to run slow like with clamscan
    //     active: false, // you don't want to use this at all because it's evil
    //     bypass_test: true, // Don't check to see if socket is available. You should probably never set this to true.
    // },
    preference: 'clamscan' 
};


async function some_function() {
    try {
        // Get instance by resolving ClamScan promise object
        console.log("-------------------hello world------------------------------");
        const clamscan = await new NodeClam().init(options);
        //console.log(clamscan);
        console.log("--------------------------------------------------------hello world------------------------------------------------");
        const {good_files, bad_files} = await clamscan.scan_dir('/home/abhishek/Desktop/JSINFO', );
        console.log("----------------------------------------------------------hello world--------------------------------------------------------------------");
        console.log(good_files);
    } catch (err) {
       console.log(err);
    }
};
 
some_function();

但是,我收到这样的错误:

节点蛤:标准输出:节点蛤:<未知文件路径!>被感染!(节点:109042)UnhandledPromiseRejectionWarning:错误:错误:产生 /usr/bin/clamscan --no-summary --stdout。

在位置 /usr/bin/clamscan 中有一个 clamscan 文件。但这仍然来了

4

1 回答 1

0

我通过使用 Promise 函数而不是异步函数成功让 scan_dir 工作......我猜这是库中的一个问题,但如果你使用它,它应该可以工作:)

const NodeClam = require('clamscan');
const ClamScan = new NodeClam().init();


function main() {
  // Get instance by resolving ClamScan promise object
  ClamScan.then(async clamscan => {
      try {
          // You can re-use the `clamscan` object as many times as you want
          const path = '/path/to/your/folder';
          const version = await clamscan.get_version();
          console.log(`ClamAV Version: ${version}`);
  
          clamscan.scan_dir(path, (err, good_files, bad_files, viruses) => {
            if (err) return console.error(err);

            console.log(good_files);
        
            if (bad_files.length > 0) {
                console.log(`${path} was infected. The offending files (${bad_files.join (', ')}) have been quarantined.`);
                console.log(`Viruses Found: ${viruses.join(', ')}`);
            } else {
                console.log("Everything looks good! No problems here!.");
            }
          });
      } catch (err) {
          // Handle any errors raised by the code in the try block
      }
  }).catch(err => {
      // Handle errors that may have occurred during initialization
  });
}

main();

问候

于 2021-02-22T10:40:01.050 回答