{"id":22281831,"url":"https://github.com/kylefarris/clamscan","last_synced_at":"2025-04-10T04:49:35.286Z","repository":{"id":10451191,"uuid":"12620641","full_name":"kylefarris/clamscan","owner":"kylefarris","description":"A robust ClamAV virus scanning library supporting scanning files, directories, and streams with local sockets, local/remote TCP, and local clamscan/clamdscan binaries (with failover).","archived":false,"fork":false,"pushed_at":"2024-10-21T16:17:13.000Z","size":843,"stargazers_count":251,"open_issues_count":12,"forks_count":76,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T02:32:18.239Z","etag":null,"topics":["callback","clamav","clamdscan-daemon","nodejs","passthrough-stream","streams","tcp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kylefarris.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-05T14:59:56.000Z","updated_at":"2025-03-24T10:13:43.000Z","dependencies_parsed_at":"2023-01-13T15:57:08.486Z","dependency_job_id":"ecc92f06-9350-42ee-beb3-12b53fc74fe4","html_url":"https://github.com/kylefarris/clamscan","commit_stats":{"total_commits":314,"total_committers":29,"mean_commits":"10.827586206896552","dds":0.5414012738853503,"last_synced_commit":"e04d635a8db1c477047c89a76c24fc581e9ca03f"},"previous_names":[],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefarris%2Fclamscan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefarris%2Fclamscan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefarris%2Fclamscan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefarris%2Fclamscan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kylefarris","download_url":"https://codeload.github.com/kylefarris/clamscan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161243,"owners_count":21057552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["callback","clamav","clamdscan-daemon","nodejs","passthrough-stream","streams","tcp"],"created_at":"2024-12-03T16:22:32.322Z","updated_at":"2025-04-10T04:49:35.263Z","avatar_url":"https://github.com/kylefarris.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeJS Clamscan Virus Scanning Utility\n\n[![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-image]][node-url] [![Test Suite](https://github.com/kylefarris/clamscan/actions/workflows/test.yml/badge.svg)](https://github.com/kylefarris/clamscan/actions/workflows/test.yml)\n\nUse Node JS to scan files on your server with ClamAV's clamscan/clamdscan binary or via TCP to a remote server or local UNIX Domain socket. This is especially useful for scanning uploaded files provided by un-trusted sources.\n\n# !!IMPORTANT\n\nIf you are using a version prior to 1.2.0, please upgrade! There was a security vulnerability in previous versions that can cause false negative in some edge cases. Specific details on how the attack could be implemented will not be disclosed here. Please update to 1.2.0 or greater ASAP. No breaking changes are included, only the security patch.\n\nAll older versions in NPM have been deprecated.\n\n# Version 1.0.0 Information\n\nIf you are migrating from v0.8.5 or less to v1.0.0 or greater, please read the [release notes](https://github.com/kylefarris/clamscan/releases/tag/v1.0.0) as there are some breaking changes (but also some awesome new features!).\n\n# Table of Contents\n\n- [Dependencies](#dependencies)\n  - [Local Binary Method](#to-use-local-binary-method-of-scanning)\n  - [TCP/Domain Socket Method](#to-use-clamav-using-tcp-sockets)\n- [How to Install](#how-to-install)\n- [License Info](#license-info)\n- [Getting Started](#getting-started)\n  - [A note about using this module via sockets or TCP](#a-note-about-using-this-module-via-sockets-or-tcp)\n- [Basic Usage Example](#basic-usage-example)\n- [API](#api)\n  - [getVersion](#getVersion)\n  - [isInfected (alias: scanFile)](#isInfected)\n  - [scanDir](#scanDir)\n  - [scanFiles](#scanFiles)\n  - [scanStream](#scanStream)\n  - [passthrough](#passthrough)\n  - [ping](#ping)\n- [Contribute](#contribute)\n- [Resources used to help develop this module](#resources-used-to-help-develop-this-module)\n\n# Dependencies\n\n## To use local binary method of scanning\n\nYou will need to install ClamAV's clamscan binary and/or have clamdscan daemon running on your server. On linux, it's quite simple.\n\nFedora-based distros:\n\n```bash\nsudo yum install clamav\n```\n\nDebian-based distros:\n\n```bash\nsudo apt-get install clamav clamav-daemon\n```\n\nFor OS X, you can install clamav with brew:\n\n```bash\nsudo brew install clamav\n```\n\n## To use ClamAV using TCP sockets\n\nYou will need access to either:\n\n1. A local UNIX Domain socket for a local instance of `clamd`\n\n- Follow instructions in [To use local binary method of scanning](#user-content-to-use-local-binary-method-of-scanning).\n- Socket file is usually: `/var/run/clamd.scan/clamd.sock`\n- Make sure `clamd` is running on your local server\n\n2. A local/remote `clamd` daemon\n\n- Must know the port the daemon is running on\n- If running on remote server, you must have the IP address/domain name\n- If running on remote server, it's firewall must have the appropriate TCP port(s) open\n- Make sure `clamd` is running on your local/remote server\n\n**NOTE:** This module is not intended to work on a Windows server. This would be a welcome addition if someone wants to add that feature (I may get around to it one day but have no urgent need for this).\n\n# How to Install\n\n```bash\nnpm install clamscan\n```\n\n# License Info\n\nLicensed under the MIT License:\n\n- \u003chttp://www.opensource.org/licenses/mit-license.php\u003e\n\n# Getting Started\n\nAll of the values listed in the example below represent the default values for their respective configuration item.\n\nYou can simply do this:\n\n```javascript\nconst NodeClam = require('clamscan');\nconst ClamScan = new NodeClam().init();\n```\n\nAnd, you'll be good to go.\n\n**BUT**: If you want more control, you can specify all sorts of options.\n\n```javascript\nconst NodeClam = require('clamscan');\nconst ClamScan = new NodeClam().init({\n    removeInfected: false, // If true, removes infected files\n    quarantineInfected: false, // False: Don't quarantine, Path: Moves files to this place.\n    scanLog: null, // Path to a writeable log file to write scan results into\n    debugMode: false, // Whether or not to log info/debug/error msgs to the console\n    fileList: null, // path to file containing list of files to scan (for scanFiles method)\n    scanRecursively: true, // If true, deep scan folders recursively\n    clamscan: {\n        path: '/usr/bin/clamscan', // Path to clamscan binary on your server\n        db: null, // Path to a custom virus definition database\n        scanArchives: true, // If true, scan archives (ex. zip, rar, tar, dmg, iso, etc...)\n        active: true // If true, this module will consider using the clamscan binary\n    },\n    clamdscan: {\n        socket: false, // Socket file for connecting via TCP\n        host: false, // IP of host to connect to TCP interface\n        port: false, // Port of host to use when connecting via TCP interface\n        timeout: 60000, // Timeout for scanning files\n        localFallback: true, // Use local preferred binary to scan if socket/tcp fails\n        path: '/usr/bin/clamdscan', // Path to the clamdscan binary on your server\n        configFile: null, // Specify config file if it's in an unusual place\n        multiscan: true, // Scan using all available cores! Yay!\n        reloadDb: false, // If true, will re-load the DB on every call (slow)\n        active: true, // If true, this module will consider using the clamdscan binary\n        bypassTest: false, // Check to see if socket is available when applicable\n        tls: false, // Use plaintext TCP to connect to clamd\n    },\n    preference: 'clamdscan' // If clamdscan is found and active, it will be used by default\n});\n```\n\nHere is a _non-default values example_ (to help you get an idea of what proper-looking values could be):\n\n```javascript\nconst NodeClam = require('clamscan');\nconst ClamScan = new NodeClam().init({\n    removeInfected: true, // Removes files if they are infected\n    quarantineInfected: '~/infected/', // Move file here. removeInfected must be FALSE, though.\n    scanLog: '/var/log/node-clam', // You're a detail-oriented security professional.\n    debugMode: true, // This will put some debug info in your js console\n    fileList: '/home/webuser/scanFiles.txt', // path to file containing list of files to scan\n    scanRecursively: false, // Choosing false here will save some CPU cycles\n    clamscan: {\n        path: '/usr/bin/clam', // I dunno, maybe your clamscan is just call \"clam\"\n        scanArchives: false, // Choosing false here will save some CPU cycles\n        db: '/usr/bin/better_clam_db', // Path to a custom virus definition database\n        active: false // you don't want to use this at all because it's evil\n    },\n    clamdscan: {\n        socket: '/var/run/clamd.scan/clamd.sock', // This is pretty typical\n        host: '127.0.0.1', // If you want to connect locally but not through socket\n        port: 12345, // Because, why not\n        timeout: 300000, // 5 minutes\n        localFallback: false, // Do no fail over to binary-method of scanning\n        path: '/bin/clamdscan', // Special path to the clamdscan binary on your server\n        configFile: '/etc/clamd.d/daemon.conf', // A fairly typical config location\n        multiscan: false, // You hate speed and multi-threaded awesome-sauce\n        reloadDb: true, // You want your scans to run slow like with clamscan\n        active: false, // you don't want to use this at all because it's evil\n        bypassTest: true, // Don't check to see if socket is available. You should probably never set this to true.\n        tls: true, // Connect to clamd over TLS\n    },\n    preference: 'clamscan' // If clamscan is found and active, it will be used by default\n});\n```\n\nNOTE: If a valid `port` is provided but no `host` value is provided, the clamscan will assume `'localhost'` for `host`.\n\n## A note about using this module via sockets or TCP\n\nAs of version v1.0.0, this module supports communication with a local or remote ClamAV daemon through Unix Domain sockets or a TCP host/port combo. If you supply both in your configuration object, the UNIX Domain socket option will be used. The module _will not_ not fallback to using the alternative Host/Port method. If you wish to connect via Host/Port and not a Socket, please either omit the `socket` property in the config object or use `socket: null`.\n\nIf you specify a valid clamscan/clamdscan binary in your config and you set `clamdscan.localFallback: true` in your config, this module _will_ fallback to the traditional way this module has worked--using a binary directly/locally.\n\nAlso, there are some caveats to using the socket/tcp based approach:\n\n- The following configuration items are not honored (unless the module falls back to binary method):\n\n  - `removeInfected` - remote clamd service config will dictate this\n  - `quarantineInfected` - remote clamd service config will dictate this\n  - `scanLog` - remote clamd service config will dictate this\n  - `fileList` - this simply won't be available\n  - `clamscan.db` - only available on fallback\n  - `clamscan.scanArchives` - only available on fallback\n  - `clamscan.path` - only available on fallback\n  - `clamdscan.configFile` - only available on fallback\n  - `clamdscan.path` - only available on fallback\n\n# Basic Usage Example\n\nFor the sake of brevity, all the examples in the [API](#api) section will be shortened to just the relevant parts related specifically to that example. In those examples, we'll assume you already have an instance of the `clamscan` object. Since initializing the module returns a promise, you'll have to resolve that promise to get an instance of the `clamscan` object.\n\n**Below is the _full_ example of how you could get that instance and run some methods:**\n\n```javascript\nconst NodeClam = require('clamscan');\nconst ClamScan = new NodeClam().init(options);\n\n// Get instance by resolving ClamScan promise object\nClamScan.then(async clamscan =\u003e {\n    try {\n        // You can re-use the `clamscan` object as many times as you want\n        const version = await clamscan.getVersion();\n        console.log(`ClamAV Version: ${version}`);\n\n        const {isInfected, file, viruses} = await clamscan.isInfected('/some/file.zip');\n        if (isInfected) console.log(`${file} is infected with ${viruses}!`);\n    } catch (err) {\n        // Handle any errors raised by the code in the try block\n    }\n}).catch(err =\u003e {\n    // Handle errors that may have occurred during initialization\n});\n```\n\n**If you're writing your code within an async function, getting an instance can be one less step:**\n\n```javascript\nconst NodeClam = require('clamscan');\n\nasync some_function() {\n    try {\n        // Get instance by resolving ClamScan promise object\n        const clamscan = await new NodeClam().init(options);\n        const {goodFiles, badFiles} = await clamscan.scanDir('/foo/bar');\n    } catch (err) {\n        // Handle any errors raised by the code in the try block\n    }\n}\n\nsome_function();\n```\n\n# API\n\nComplete/functional examples for various use-cases can be found in the [examples folder](https://github.com/kylefarris/clamscan/tree/master/examples).\n\n\u003ca name=\"getVersion\"\u003e\u003c/a\u003e\n\n## .getVersion([callback])\n\nThis method allows you to determine the version of ClamAV you are interfacing with. It supports a callback and Promise API. If no callback is supplied, a Promise will be returned.\n\n### Parameters\n\n- `callback` (function) (optional) Will be called when the scan is complete. It receives 2 parameters:\n\n  - `err` (object or null) A standard javascript Error object (null if no error)\n  - `version` (string) The version of the clamav server you're interfacing with\n\n### Returns\n\n- Promise\n\n  - Promise resolution returns: `version` (string) The version of the clamav server you're interfacing with\n\n### Callback Example\n\n```javascript\nclamscan.getVersion((err, version) =\u003e {\n    if (err) return console.error(err);\n    console.log(`ClamAV Version: ${version}`);\n});\n```\n\n### Promise Example\n\n```javascript\nclamscan.getVersion().then(version =\u003e {\n    console.log(`ClamAV Version: ${version}`);\n}).catch(err =\u003e {\n    console.error(err);\n});\n```\n\n\u003ca name=\"isInfected\"\u003e\u003c/a\u003e\n\n## .isInfected(filePath[,callback])\n\nThis method allows you to scan a single file. It supports a callback and Promise API. If no callback is supplied, a Promise will be returned. This method will likely be the most common use-case for this module.\n\n### Alias\n\n`.scan_file`\n\n### Parameters\n\n- `filePath` (string) Represents a path to the file to be scanned.\n- `callback` (function) (optional) Will be called when the scan is complete. It takes 3 parameters:\n\n  - `err` (object or null) A standard javascript Error object (null if no error)\n  - `file` (string) The original `filePath` passed into the `isInfected` method.\n  - `isInfected` (boolean) **True**: File is infected; **False**: File is clean. **NULL**: Unable to scan.\n  - `viruses` (array) An array of any viruses found in the scanned file.\n\n### Returns\n\n- Promise\n\n  - Promise resolution returns: `result` (object):\n\n    - `file` (string) The original `filePath` passed into the `isInfected` method.\n    - `isInfected` (boolean) **True**: File is infected; **False**: File is clean. **NULL**: Unable to scan.\n    - `viruses` (array) An array of any viruses found in the scanned file.\n\n### Callback Example\n\n```javascript\nclamscan.isInfected('/a/picture/for_example.jpg', (err, file, isInfected, viruses) =\u003e {\n    if (err) return console.error(err);\n\n    if (isInfected) {\n        console.log(`${file} is infected with ${viruses.join(', ')}.`);\n    }\n});\n```\n\n### Promise Example\n\n```javascript\nclamscan.isInfected('/a/picture/for_example.jpg').then(result =\u003e {\n    const {file, isInfected, viruses} =  result;\n    if (isInfected) console.log(`${file} is infected with ${viruses.join(', ')}.`);\n}).then(err =\u003e {\n    console.error(err);\n})\n```\n\n### Async/Await Example\n\n```javascript\nconst {file, isInfected, viruses} = await clamscan.isInfected('/a/picture/for_example.jpg');\n```\n\n\u003ca name=\"scanDir\"\u003e\u003c/a\u003e\n\n## .scanDir(dirPath[,endCallback[,fileCallback]])\n\nAllows you to scan an entire directory for infected files. This obeys your `recursive` option even for `clamdscan` which does not have a native way to turn this feature off. If you have multiple paths, send them in an array to `scanFiles`.\n\n**TL;DR:** For maximum speed, don't supply a `fileCallback`.\n\nIf you choose to supply a `fileCallback`, the scan will run a little bit slower (depending on number of files to be scanned) for `clamdscan`. If you are using `clamscan`, while it will work, I'd highly advise you to NOT pass a `fileCallback`... it will run incredibly slow.\n\n### NOTE\n\nThe `goodFiles` parameter of the `endCallback` callback in this method will only contain the directory that was scanned in **all** **but** the following scenarios:\n\n- A `fileCallback` callback is provided, and `scanRecursively` is set to _true_.\n- The scanner is set to `clamdscan` and `scanRecursively` is set to _false_.\n- The scanned directory contains 1 or more viruses. In this case, the `goodFiles` array will be empty.\n\nThere will, however, be a total count of the good files which is calculated by determining the total number of files scanned and subtracting the number of bad files from that count. We simply can't provide a list of all good files due to the potential large memory usage implications of scanning a directory with, for example, _millions_ of files.\n\n### Parameters\n\n- `dirPath` (string) (required) Full path to the directory to scan.\n- `endCallback` (function) (optional) Will be called when the entire directory has been completely scanned. This callback takes 3 parameters:\n\n  - `err` (object) A standard javascript Error object (null if no error)\n  - `goodFiles` (array) An *empty* array if path is _infected_. An array containing the directory name that was passed in if _clean_.\n  - `badFiles` (array) List of the full paths to all files that are _infected_.\n  - `viruses` (array) List of all the viruses found (feature request: associate to the bad files).\n  - `numGoodFiles` (number) Number of files that were found to be clean.\n\n- `fileCallback` (function) (optional) Will be called after each file in the directory has been scanned. This is useful for keeping track of the progress of the scan. This callback takes 3 parameters:\n\n  - `err` (object or null) A standard Javascript Error object (null if no error)\n  - `file` (string) Path to the file that just got scanned.\n  - `isInfected` (boolean) **True**: File is infected; **False**: File is clean. **NULL**: Unable to scan file.\n\n### Returns\n\n- Promise\n\n  - Promise resolution returns: `result` (object):\n\n    - `path` (string) The original `dir_path` passed into the `scanDir` method.\n    - `isInfected` (boolean) **True**: File is infected; **False**: File is clean. **NULL**: Unable to scan.\n    - `goodFiles` (array) An *empty* array if path is _infected_. An array containing the directory name that was passed in if _clean_.\n    - `badFiles` (array) List of the full paths to all files that are _infected_.\n    - `viruses` (array) List of all the viruses found (feature request: associate to the bad files).\n    - `numGoodFiles` (number) Number of files that were found to be clean.\n\n### Callback Example\n\n```javascript\nclamscan.scanDir('/some/path/to/scan', (err, goodFiles, badFiles, viruses, numGoodFiles) {\n    if (err) return console.error(err);\n\n    if (badFiles.length \u003e 0) {\n        console.log(`${path} was infected. The offending files (${badFiles.join (', ')}) have been quarantined.`);\n        console.log(`Viruses Found: ${viruses.join(', ')}`);\n    } else {\n        console.log(`${goodFiles[0]} looks good! ${numGoodFiles} file scanned and no problems found!.`);\n    }\n});\n```\n\n### Promise Example\n\n```javascript\nclamscan.scanDir('/some/path/to/scan').then(results =\u003e {\n    const { path, isInfected, goodFiles, badFiles, viruses, numGoodFiles } = results;\n    //...\n}).catch(err =\u003e {\n    return console.error(err);\n});\n```\n\n### Async/Await Example\n\n```javascript\nconst { path, isInfected, goodFiles, badFiles, viruses, numGoodFiles } = await clamscan.scanDir('/some/path/to/scan');\n```\n\n\u003ca name=\"scanFiles\"\u003e\u003c/a\u003e\n\n## .scanFiles(files[,endCallback[,fileCallback]])\n\nThis allows you to scan many files that might be in different directories or maybe only certain files of a single directory. This is essentially a wrapper for `isInfected` that simplifies the process of scanning many files or directories.\n\n### Parameters\n\n- `files` (array) (optional) A list of strings representing full paths to files you want scanned. If not supplied, the module will check for a `fileList` config option. If neither is found, the method will throw an error.\n- `endCallback` (function) (optional) Will be called when the entire list of files has been completely scanned. This callback takes 3 parameters:\n\n  - `err` (object or null) A standard JavaScript Error object (null if no error)\n  - `goodFiles` (array) List of the full paths to all files that are _clean_.\n  - `badFiles` (array) List of the full paths to all files that are _infected_.\n\n- `fileCallback` (function) (optional) Will be called after each file in the list has been scanned. This is useful for keeping track of the progress of the scan. This callback takes 3 parameters:\n\n  - `err` (object or null) A standard JavaScript Error object (null if no error)\n  - `file` (string) Path to the file that just got scanned.\n  - `isInfected` (boolean) **True**: File is infected; **False**: File is clean. **NULL**: Unable to scan file.\n\n### Returns\n\n- Promise\n\n  - Promise resolution returns: `result` (object):\n\n    - `goodFiles` (array) List of the full paths to all files that are _clean_.\n    - `badFiles` (array) List of the full paths to all files that are _infected_.\n    - `errors` (object) Per-file errors keyed by the filename in which the error happened. (ex. `{'foo.txt': Error}`)\n    - `viruses` (array) List of all the viruses found (feature request: associate to the bad files).\n\n### Callback Example\n\n```javascript\nconst scan_status = { good: 0, bad: 0 };\nconst files = [\n    '/path/to/file/1.jpg',\n    '/path/to/file/2.mov',\n    '/path/to/file/3.rb'\n];\nclamscan.scanFiles(files, (err, goodFiles, badFiles, viruses) =\u003e {\n    if (err) return console.error(err);\n    if (badFiles.length \u003e 0) {\n        console.log({\n            msg: `${goodFiles.length} files were OK. ${badFiles.length} were infected!`,\n            badFiles,\n            goodFiles,\n            viruses,\n        });\n    } else {\n        res.send({msg: \"Everything looks good! No problems here!.\"});\n    }\n}, (err, file, isInfected, viruses) =\u003e {\n    ;(isInfected ? scan_status.bad++ : scan_status.good++);\n    console.log(`${file} is ${(isInfected ? `infected with ${viruses}` : 'ok')}.`);\n    console.log('Scan Status: ', `${(scan_status.bad + scan_status.good)}/${files.length}`);\n});\n```\n\n### Promise Example\n\n**Note:** There is currently no way to get per-file notifications with the Promise API.\n\n```javascript\nclamscan.scanFiles(files).then(results =\u003e {\n    const { goodFiles, badFiles, errors, viruses } = results;\n    // ...\n}).catch(err =\u003e {\n    console.error(err);\n})\n```\n\n### Async/Await Example\n\n```javascript\nconst { goodFiles, badFiles, errors, viruses } = await clamscan.scanFiles(files);\n```\n\n#### Scanning files listed in fileList\n\nIf this modules is configured with a valid path to a file containing a newline-delimited list of files, it will use the list in that file when scanning if the first paramter passed is falsy.\n\n**Files List Document:**\n\n```bash\n/some/path/to/file.zip\n/some/other/path/to/file.exe\n/one/more/file/to/scan.rb\n```\n\n**Script:**\n\n```javascript\nconst ClamScan = new NodeClam().init({\n    fileList: '/path/to/fileList.txt'\n});\n\nClamScan.then(async clamscan =\u003e {\n    // Supply nothing to first parameter to use `fileList`\n    const { goodFiles, badFiles, errors, viruses } = await clamscan.scanFiles();\n});\n```\n\n\u003ca name=\"scanStream\"\u003e\u003c/a\u003e\n\n## .scanStream(stream[,callback])\n\nThis method allows you to scan a binary stream. **NOTE**: This method will only work if you've configured the module to allow the use of a TCP or UNIX Domain socket. In other words, this will not work if you only have access to a local ClamAV binary.\n\n### Parameters\n\n- `stream` (stream) A readable stream object\n- `callback` (function) (optional) Will be called after the stream has been scanned (or attempted to be scanned):\n\n  - `err` (object or null) A standard JavaScript Error object (null if no error)\n  - `isInfected` (boolean) **True**: Stream is infected; **False**: Stream is clean. **NULL**: Unable to scan file.\n\n### Returns\n\n- Promise\n\n  - Promise resolution returns: `result` (object):\n\n    - `file` (string) **NULL** as no file path can be provided with the stream\n    - `isInfected` (boolean) **True**: File is infected; **False**: File is clean. **NULL**: Unable to scan.\n    - `viruses` (array) An array of any viruses found in the scanned file.\n\n### Examples\n\n**Callback Example:**\n\n```javascript\nconst NodeClam = require('clamscan');\n\n// You'll need to specify your socket or TCP connection info\nconst clamscan = new NodeClam().init({\n    clamdscan: {\n        socket: '/var/run/clamd.scan/clamd.sock',\n        host: '127.0.0.1',\n        port: 3310,\n    }\n});\nconst Readable = require('stream').Readable;\nconst rs = Readable();\n\nrs.push('foooooo');\nrs.push('barrrrr');\nrs.push(null);\n\nclamscan.scanStream(stream, (err, { isInfected. viruses }) =\u003e {\n    if (err) return console.error(err);\n    if (isInfected) return console.log('Stream is infected! Booo!', viruses);\n    console.log('Stream is not infected! Yay!');\n});\n```\n\n**Promise Example:**\n\n```javascript\nclamscan.scanStream(stream).then(({isInfected}) =\u003e {\n    if (isInfected) return console.log(\"Stream is infected! Booo!\");\n    console.log(\"Stream is not infected! Yay!\");\n}).catch(err =\u003e {\n    console.error(err);\n};\n```\n\n**Promise Example:**\n\n```javascript\nconst { isInfected, viruses } = await clamscan.scanStream(stream);\n```\n\n\u003ca name=\"passthrough\"\u003e\u003c/a\u003e\n\n## .passthrough()\n\nThe `passthrough` method returns a PassthroughStream object which allows you pipe a ReadbleStream through it and on to another output. In the case of this module's passthrough implementation, it's actually forking the data to also go to ClamAV via TCP or Domain Sockets. Each data chunk is only passed on to the output if that chunk was successfully sent to and received by ClamAV. The PassthroughStream object returned from this method has a special event that is emitted when ClamAV finishes scanning the streamed data so that you can decide if there's anything you need to do with the final output destination (ex. delete a file or S3 object).\n\nIn typical, non-passthrough setups, a file is uploaded to the local filesytem and then subsequently scanned. With that setup, you have to wait for the upload to complete _and then wait again_ for the scan to complete. Using this module's `passthrough` method, you could theoretically speed up user uploads intended to be scanned by up to 2x because the files are simultaneously scanned and written to any WriteableStream output (examples: filesystem, S3, gzip, etc...).\n\nAs for these theoretical gains, your mileage my vary and I'd love to hear feedback on this to see where things can still be improved.\n\nPlease note that this method is different than all the others in that it returns a PassthroughStream object and does not support a Promise or Callback API. This makes sense once you see the example below (a practical working example can be found in the examples directory of this module):\n\n### Example\n\n```javascript\nconst NodeClam = require('clamscan');\n\n// You'll need to specify your socket or TCP connection info\nconst clamscan = new NodeClam().init({\n    clamdscan: {\n        socket: '/var/run/clamd.scan/clamd.sock',\n        host: '127.0.0.1',\n        port: 3310,\n    }\n});\n\n// For example's sake, we're using the Axios module\nconst axios = require('Axios');\n\n// Get a readable stream for a URL request\nconst input = axios.get(some_url);\n\n// Create a writable stream to a local file\nconst output = fs.createWriteStream(some_local_file);\n\n// Get instance of this module's PassthroughStream object\nconst av = clamscan.passthrough();\n\n// Send output of Axios stream to ClamAV.\n// Send output of Axios to `some_local_file` if ClamAV receives data successfully\ninput.pipe(av).pipe(output);\n\n// What happens when scan is completed\nav.on('scan-complete', result =\u003e {\n   const { isInfected, viruses } = result;\n   // Do stuff if you want\n});\n\n// What happens when data has been fully written to `output`\noutput.on('finish', () =\u003e {\n    // Do stuff if you want\n});\n\n// NOTE: no errors (or other events) are being handled in this example but standard errors will be emitted according to NodeJS's Stream specifications\n```\n\n\u003ca name=\"ping\"\u003e\u003c/a\u003e\n\n## .ping()\n\nThis method checks to see if the remote/local socket is working. It supports a callback and Promise API. If no callback is supplied, a Promise will be returned. This method can be used for healthcheck purposes and is already implicitly used during scan.\n\n### Parameters\n\n- `callback` (function) (optional) Will be called after the ping:\n\n  - `err` (object or null) A standard JavaScript Error object (null if no error)\n  - `client` (object) A copy of the Socket/TCP client\n\n### Returns\n\n- Promise\n\n  - Promise resolution returns: `client` (object): A copy of the Socket/TCP client\n\n### Examples\n\n**Callback Example:**\n\n```javascript\nconst NodeClam = require('clamscan');\n\n// You'll need to specify your socket or TCP connection info\nconst clamscan = new NodeClam().init({\n    clamdscan: {\n        socket: '/var/run/clamd.scan/clamd.sock',\n        host: '127.0.0.1',\n        port: 3310,\n    }\n});\n\nclamscan.ping((err, client) =\u003e {\n    if (err) return console.error(err);\n    console.log('ClamAV is still working!');\n    client.end();\n});\n```\n\n**Promise Example:**\n\n```javascript\nclamscan.ping().then((client) =\u003e {\n    console.log('ClamAV is still working!');\n    client.end();\n}).catch(err =\u003e {\n    console.error(err);\n};\n```\n\n**Promise Example:**\n\n```javascript\nconst client = await clamscan.ping();\nclient.end();\n```\n\n# Contribute\n\nGot a missing feature you'd like to use? Found a bug? Go ahead and fork this repo, build the feature and issue a pull request.\n\n# Resources used to help develop this module\n\n- \u003chttps://stuffivelearned.org/doku.php?id=apps:clamav:general:remoteclamdscan\u003e\n- \u003chttp://cpansearch.perl.org/src/JMEHNLE/ClamAV-Client-0.11/lib/ClamAV/Client.pm\u003e\n- \u003chttps://github.com/yongtang/clamav.js\u003e\n- \u003chttps://nodejs.org/dist/latest-v10.x/docs/api/stream.html\u003e\n- \u003chttps://manpages.debian.org/jessie/clamav-daemon/clamd.8.en.html\u003e\n\n[node-image]: https://img.shields.io/node/v/clamscan.svg\n[node-url]: https://nodejs.org/en/download\n[npm-downloads-image]: https://img.shields.io/npm/dm/clamscan.svg\n[npm-url]: https://npmjs.org/package/clamscan\n[npm-version-image]: https://img.shields.io/npm/v/clamscan.svg\n[travis-image]: https://img.shields.io/travis/kylefarris/clamscan/master.svg\n[travis-url]: https://travis-ci.org/kylefarris/clamscan\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylefarris%2Fclamscan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkylefarris%2Fclamscan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylefarris%2Fclamscan/lists"}