This file is a manually maintained list of changes for each release. Feel free to add your changes here when sending pull requests. Also send corrections if you spot any mistakes.
- ClamAV returns an exit code 1 when it detects a virus but
exec
was interpreting that response as an error. Checking the response with type-sensitive equivalence resolves this bug.
- Fixed documentation
- Corrected the installation instructions for
clamav
. Thank you @jshamley! - Fixed major bug preventing the
scan_dir
method from working properly - Corrected documentation describing how to instantiate this module.
- Deprecated the
quarantine_path
option. Please only usequarantine_infected
for now on. - Updated documentation to reflect above change.
NOTE: There are some breaking changes on this release. Since this is still a pre-version 1 release, I decided to only do a minor bump to 0.4.0
- The ability to run "forked" instances of
clamscan
has been removed because of irregularities with different systems--namely if you hadmax_forks
set to 3, it would sometimes only scan the first or last file in the group... not good. - Added the ability to use
clamdscan
. This ultimately negates the downside of removing the forking capability mentioned in item one. This is a really big improvement (many orders of magnitude) if your system has access to theclamdscan
daemon. - Added a
file_list
option allowing one to specify a text file that lists (one per line) paths to files to be scanned. This is great if you need to scan hundreds or thousands of random files. clam_path
option has been moved toclam.path
db
option has been moved toclam.db
scan_archives
option has been moved toclam.scan_archives
scan_files
now supports directories as well and will obey yourscan_recursively
option.
- Updated description in package.json file.
- Fixed major bug in the scan_files method that was causing it to only scan half the files passed to it.
- Removed the unnecessary "index_old.js" file put there for reference during the 0.5.0 -> 0.6.0 semi-rewrite.
- Fixed error messages
- Fixed a bug caused by not passing a
file_cb
paramter to thescan_file
method. Thanks nicolaspeixoto! - Added tests
- Fixed poor validation of method parameters
- Changed API of
scan_dir
such that the paramaters passed to theend_cb
are different in certain defined situations. See the "NOTE" section of thescan_dir
documentation for details. - Changed
err
paramter in all callbacks from a simple string to a proper javascriptError
object. - Added documentation for how to use a file_list file for scanning.
- Added node dependency of > 0.12 to
package.json
file
- Removed item causing node > 0.12 dependency.
- Removed dependency of node > 0.12 in
package.json
file.
- Fixed check for database file. Issue #6
- Updated to
execFile
instead ofexec
- Improved test suite
- Added support for TCP/UNIX Domain socket communication to local or remote clamav services.
- Added a
get_version
method. - NULL is now returned to the third parameter of the
is_infected
when file is neither infected or clean (i.e. on unexpected response) - Created alias:
scan_file
foris_infected
. - Created a
scan_stream
method. - Minor code clean-up
This is a huge major release in which this module was essentially completely re-written. This version introduces some breaking changes and major new features. Please read the release notes below carefully.
-
Now requires at least Node v10.0.0
-
Code re-written in ES2018 code
-
Now supports a hybrid Promise/Callback API (supports async/await)
-
Now properly supports TCP/UNIX Domain socket communication to local or remote clamav services (with optional fallback to local binary via child process).
-
Added new
scan_stream
method which allows you to pass an input stream. -
Added new
get_version
method which allows you to check the version of ClamAV that you'll be communicating with. -
Added new
passthrough
method which allows you to pipe a stream "through" the clamscan module and on to another destination (ex. S3). -
Added new alias
scan_file
that points tois_infected
. -
In order to provide the name of any viruses found, a new standard
viruses
array is now be provided to the callback for:is_infected
&scan_file
methods (callback format:(err, file, is_infected, viruses) => { ... }
).scan_files
method (callback format:(err, good_files, bad_files, error_files, viruses) => { ... }
).scan_dir
method (callback format:(err, good_files, bad_files, viruses) => { ... }
).
-
In all cases, the
viruses
parameter will be an empty array on error or when no viruses are found. -
scan_files
now has another additional parameter in its callback:error_files
: An object keyed by the filenames that presented errors while scanning. The value of those keys will be the error message for that file.
-
Introduces new API to instantiate the module (NOTE: The old way will no longer work! See below for more info).
For some full-fledged examples of how the new API works, checkout the /examples
directory in the module root directory.
const clamscan = require('clamscan')(options);
NOTE: Due to the new asynchronous nature of the checks that are performed upon initialization of the module, the initialization method now returns a Promise instead of the actual instantiated object. Resolving the Promise with then
will return the object like before.
const NodeClam = require('clamscan');
const ClamScan = new NodeClam().init(options);
clamscan.is_infected('/path/to/file.txt', (err, file, is_infected) => {
// Do stuff
});
ClamScan.then(clamscan => {
clamscan.is_infected('/path/to/file.txt', (err, file, is_infected, viruses) => {
// Do stuff
});
});
If you prefer the async/await style of coding:
;(async () => {
const clamscan = await new NodeClam().init(options);
clamscan.is_infected('/path/to/file.txt', (err, file, is_infected, viruses) => {
// Do stuff
});
})();
The only way to get results/errors in pre-1.0.0 was through callbacks.
const clamscan = require('clamscan')(options);
clamscan.scan_dir('/path/to/directory', (err, good_files, bad_files) => {
// Do stuff inside callback
});
In version 1.0.0 and beyond, you will now be able to use Promises as well (and, of course, async/await).
const ClamScan = new NodeClam().init(options);
ClamScan.then(clamscan =>
clamscan.scan_dir('/path/to/directory').then(result => {
const {good_files, bad_files} = result;
// Do stuff
}).catch(err => {
// Handle scan error
});
}).catch(err => {
// Handle initialization error
});
;(async () => {
try {
const clamscan = await new NodeClam().init(options);
const {good_files, bad_files} = await clamscan.scan_dir('/path/to/directory');
// Do stuff
} catch (err) {
// Handle any error
}
})();
The scan_stream
method allows you supply a readable stream to have it scanned. Theoretically any stream can be scanned this way. Like all methods, it supports callback and Promise response styles (full documentation is in README).
;(async () => {
try {
const clamscan = await new NodeClam().init(options);
const stream = new Readable();
rs.push('foooooo');
rs.push('barrrrr');
rs.push(null);
const {is_infected, viruses} = await clamscan.scan_stream(stream);
// Do stuff
} catch (err) {
// Handle any error
}
})();
;(async () => {
try {
const clamscan = await new NodeClam().init(options);
const stream = new Readable();
rs.push('foooooo');
rs.push('barrrrr');
rs.push(null);
clamscan.scan_stream(stream, (err, results) => {
if (err) {
// Handle error
} else {
const {is_infected, viruses} = results;
// Do stuff
}
});
// Do stuff
} catch (err) {
// Handle any error
}
})();
The passthrough
method allows you supply a readable stream that will be "passed-through" the clamscan module and onto another destination. In reality, the passthrough method works more like a fork stream whereby the input stream is simultaneously streamed to ClamAV and whatever is the next destination. Events are created when ClamAV is done and/or when viruses are detected so that you can decide what to do with the data on the next destination (delete if virus detected, for instance). Data is only passed through to the next generation if the data has been successfully received by ClamAV. If anything halts the data going to ClamAV (including issues caused by ClamAV), the entire pipeline is halted and events are fired.
Normally, a file is uploaded and then scanned. This method should theoretically speed up user uploads intended to be scanned by up to 2x because the files are simultaneously scanned and written to disk. Your mileage my vary.
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 (full documentation is in README).
;(async () => {
try {
const clamscan = await new NodeClam().init(options);
const request = require('request');
const input = request.get(some_url);
const output = fs.createWriteStream(some_local_file);
const av = clamscan.passthrough();
// Send output of RequestJS stream to ClamAV.
// Send output of RequestJS to `some_local_file` if ClamAV receives data successfully
input.pipe(av).pipe(output);
// What happens when scan is completed
av.on('scan-complete', result => {
const {is_infected, viruses} = result;
// Do stuff if you want
});
// What happens when data has been fully written to `output`
output.on('finish', () => {
// Do stuff if you want
});
} catch (err) {
// Handle any error
}
})();
An important security patch was released in this version which fixes a bug causing false negatives in specific edge cases. Please upgrade immediately and only use this version from this point on.
All older versions of this package have been deprecated on NPM.
This just has some bug fixes and updates to dependencies. Technically, a new 'timeout'
event was added to the passthrough
stream method, but, its not fully fleshed out and doesn't seem to work so it will remain undocumented for now.
- Updated Mocha to v8.1.1. Subsequently, the oldest version of NodeJS allowed for this module is now v10.12.0.
- Fixed issue with the method not throwing errors when testing existence and viability of remote/local socket.
All sockets clients should now close when they are done being used, fail, or timeout.
- Fixed initialization to pass a config-file option during clamav version check
- Added new contributor
- Fixed tests
Please see the GitHub Release page for this project to see changelog info starting with v2.0.0.