feat(ClamAvService): Add stream scanning methods to ClamAvService

This commit is contained in:
2025-02-05 10:49:46 +01:00
parent 8acfedd7f3
commit 6300843616
9 changed files with 123 additions and 7 deletions

View File

@@ -94,6 +94,35 @@ async function main() {
main().catch(console.error);
```
### Streaming Scanning
The `ClamAvService` now also supports scanning streams directly using two new methods:
- `scanStream(stream: NodeJS.ReadableStream)`: Scans a NodeJS stream (local file streams, network streams, etc.)
- `scanWebStream(url: string)`: Fetches a web resource as a stream and scans it
#### Example Usage
```typescript
import { ClamAvService } from '@push.rocks/smartantivirus';
import { createReadStream } from 'fs';
async function main() {
const clamService = new ClamAvService('127.0.0.1', 3310);
// Example 1: Scanning a local file stream
const fileStream = createReadStream('path/to/local/file');
const streamResult = await clamService.scanStream(fileStream);
console.log('Stream Scan Result:', streamResult);
// Example 2: Scanning a web resource
const webResult = await clamService.scanWebStream('http://example.com/file');
console.log('Web Stream Scan Result:', webResult);
}
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`.