diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..9f8a794 --- /dev/null +++ b/changelog.md @@ -0,0 +1,12 @@ +# Changelog + +## 2025-01-10 - 1.0.2 - fix(documentation) +Updated README and package metadata to reflect antivirus scanning capabilities and usage instructions. + +- Improved description in package.json and npmextra.json to better describe the antivirus scanning functionalities. +- Enhanced README.md to provide detailed installation and usage instructions, usage examples, error handling, and testing guidance. + +## 2025-01-10 - 1.0.1 - Initial Release +Initial release of the project. + +- Launched the first version with core features implemented diff --git a/npmextra.json b/npmextra.json index 136fe70..e63beb2 100644 --- a/npmextra.json +++ b/npmextra.json @@ -5,10 +5,23 @@ "githost": "code.foss.global", "gitscope": "push.rocks", "gitrepo": "smartantivirus", - "description": "a package for doing antivirus testing", + "description": "A Node.js package for integrating antivirus scanning capabilities using ClamAV, allowing in-memory file and data scanning.", "npmPackagename": "@push.rocks/smartantivirus", "license": "MIT", - "projectDomain": "push.rocks" + "projectDomain": "push.rocks", + "keywords": [ + "antivirus", + "ClamAV", + "Node.js", + "virus scanning", + "security", + "buffer scanning", + "data protection", + "HTTP requests", + "file handling", + "network communication", + "software testing" + ] } }, "npmci": { diff --git a/package.json b/package.json index 5052a38..71e5d6c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@push.rocks/smartantivirus", "version": "1.0.1", "private": false, - "description": "a package for doing antivirus testing", + "description": "A Node.js package for integrating antivirus scanning capabilities using ClamAV, allowing in-memory file and data scanning.", "main": "dist_ts/index.js", "typings": "dist_ts/index.d.ts", "type": "module", @@ -46,5 +46,18 @@ "cli.js", "npmextra.json", "readme.md" + ], + "keywords": [ + "antivirus", + "ClamAV", + "Node.js", + "virus scanning", + "security", + "buffer scanning", + "data protection", + "HTTP requests", + "file handling", + "network communication", + "software testing" ] } \ No newline at end of file diff --git a/readme.md b/readme.md index 8432c5e..0311961 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,127 @@ +```markdown # @push.rocks/smartantivirus -a package for doing antivirus testing +A package for performing antivirus testing, especially suitable for use with ClamAV. -## How to create the docs +## Install -To create docs run gitzone aidoc. +Installing `@push.rocks/smartantivirus` is straightforward. You'll need Node.js and npm installed on your machine to get started. Once they are ready, you can add the `@push.rocks/smartantivirus` package to your project by running the following command: + +```bash +npm install @push.rocks/smartantivirus +``` + +This will add the package to your project's dependencies and allow you to integrate antivirus scanning capabilities directly into your application. + +## Usage + +The `@push.rocks/smartantivirus` package provides tools to easily integrate antivirus scanning capabilities into your Node.js application by interfacing with the ClamAV daemon. Below is a comprehensive guide on how to use the features of this library. + +### Setting Up the ClamAV Daemon + +Before using this package, make sure you have ClamAV installed and running on your system. You can find installation instructions for various operating systems on the [ClamAV official website](https://www.clamav.net/documents/installing-clamav). + +After installing ClamAV, start the ClamAV daemon (`clamd`). Make sure it is configured to listen on a port accessible to your Node.js application. You can configure this in the `clamd.conf` file, typically located in `/etc/clamav/clamd.conf`. + +### Basic Usage + +The primary interface provided by the package is the `ClamAvService` class. It allows you to scan data in memory or verify the connection to the ClamAV daemon. + +```typescript +import { ClamAvService } from '@push.rocks/smartantivirus'; + +async function main() { + const clamService = new ClamAvService('127.0.0.1', 3310); // Replace with your ClamAV host and port + + // Verify connection to ClamAV + const isConnected = await clamService.verifyConnection(); + console.log(`Connection to ClamAV: ${isConnected ? 'successful' : 'failed'}`); + + if (!isConnected) { + console.error('Could not connect to ClamAV daemon. Please check your configuration.'); + return; + } + + // Scan a text string + const testString = 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'; + const scanResult = await clamService.scanString(testString); + console.log('Scan Result:', scanResult); +} + +main().catch(console.error); +``` + +**Breaking Down the Example:** + +1. **Initialization**: We start by creating an instance of the `ClamAvService` class. It takes two optional parameters: the host and port where your ClamAV daemon is running. By default, it assumes `127.0.0.1` and `3310`. + +2. **Verify Connection**: The `verifyConnection` method is called to ensure that our application can communicate with the ClamAV daemon. It returns a promise that resolves to `true` if the connection is successful, and `false` otherwise. + +3. **Scan Strings**: We utilize the `scanString` method to scan a text string (in this example, the EICAR test virus string is used). This method converts the string to a buffer and sends it to the ClamAV daemon for scanning. + +### Handling Buffers + +Below is an example demonstrating scanning raw binary data in the form of buffers: + +```typescript +import { ClamAvService } from '@push.rocks/smartantivirus'; + +async function scanBufferExample() { + const clamService = new ClamAvService(); + + // This buffer should represent the binary data you want to scan. + const buffer = Buffer.from('Sample buffer contents', 'utf8'); + + try { + const scanResult = await clamService.scanBuffer(buffer); + console.log('Buffer Scan Result:', scanResult); + } catch (error) { + console.error('Error scanning buffer:', error); + } +} + +scanBufferExample(); +``` + +**Explanation:** + +- We create an instance of `ClamAvService`. +- A buffer is created and passed to the `scanBuffer` method, which scans the in-memory data for potential viruses. + +### Error Handling and Debugging + +The methods of `ClamAvService` throw errors if there are issues with communication or processing data. Wrap your code in try-catch blocks and use appropriate logging to handle errors gracefully. + +```typescript +try { + const scanResult = await clamService.scanString('Some suspicious string...'); + console.log(`Infection Status: ${scanResult.isInfected ? 'Infected' : 'Clean'}`); + if (scanResult.isInfected) { + console.log(`Reason: ${scanResult.reason}`); + } +} catch (error) { + console.error('An error occurred during the scanning process:', error); +} +``` + +### Testing your setup + +A preconfigured test script is provided, which demonstrates how to use the package with the Tap bundle testing framework. You can find the test script in `test/test.ts`. This is configured to run with the default `@push.rocks/tapbundle` setup: + +```bash +npm run test +``` + +The tests include creating and utilizing a `ClamAvService` instance and attempts to scan the well-known EICAR test string. They ensure that the basic functionality of the package is working as intended. + +### Advanced Usage and Integration + +Beyond scanning strings and buffers, you can implement additional advanced use cases based on your specific application needs, such as integrating into web services or automating file scans in cloud environments. Consider building upon provided functionalities and adapting them to meet the requirements of your application architecture. + +With the help of Node.js worker threads or external task queues like RabbitMQ, you can distribute scanning tasks efficiently within high-traffic environments. + +### Conclusion + +`@push.rocks/smartantivirus` provides a simple yet effective way to incorporate antivirus checks into your Node.js applications, leveraging the robust ClamAV engine. With features like in-memory scanning and connection verification, you can seamlessly ensure your data security solutions are integrated into your application lifecycle. +``` +undefined \ No newline at end of file diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts new file mode 100644 index 0000000..ccfb9f9 --- /dev/null +++ b/ts/00_commitinfo_data.ts @@ -0,0 +1,8 @@ +/** + * autocreated commitinfo by @push.rocks/commitinfo + */ +export const commitinfo = { + name: '@push.rocks/smartantivirus', + version: '1.0.2', + description: 'A Node.js package for integrating antivirus scanning capabilities using ClamAV, allowing in-memory file and data scanning.' +}