feat(ClamAvService): Add support for enhanced streaming methods in ClamAvService

This commit is contained in:
2025-02-05 10:52:35 +01:00
parent 6adfcc2201
commit a2d8d1cbfd
3 changed files with 21 additions and 7 deletions

View File

@@ -96,10 +96,11 @@ main().catch(console.error);
### Streaming Scanning
The `ClamAvService` now also supports scanning streams directly using two new methods:
The `ClamAvService` supports scanning both NodeJS streams and Web API streams using three specialized 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
- `scanStream(stream: NodeJS.ReadableStream)`: Scans any NodeJS readable stream (files, network, etc.)
- `scanWebStream(webstream: ReadableStream)`: Scans a Web API ReadableStream
- `scanFileFromWebAsStream(url: string)`: Fetches and scans a file from a URL using NodeJS http/https
#### Example Usage
@@ -110,14 +111,21 @@ import { createReadStream } from 'fs';
async function main() {
const clamService = new ClamAvService('127.0.0.1', 3310);
// Example 1: Scanning a local file stream
// Example 1: Scanning a local file stream (NodeJS)
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');
// Example 2: Scanning a web resource using NodeJS http/https
const webResult = await clamService.scanFileFromWebAsStream('http://example.com/file');
console.log('Web Stream Scan Result:', webResult);
// Example 3: Scanning a Web API ReadableStream
const response = await fetch('http://example.com/file');
if (response.body) {
const webStreamResult = await clamService.scanWebStream(response.body);
console.log('Web Stream API Scan Result:', webStreamResult);
}
}
main().catch(console.error);