mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MalwareMultiScan.Shared.Interfaces;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace MalwareMultiScan.Backends.Backends.Abstracts
|
|
{
|
|
public abstract class AbstractScanBackend : IScanBackend
|
|
{
|
|
public virtual string Name => throw new NotImplementedException();
|
|
|
|
public virtual DateTime DatabaseLastUpdate => throw new NotImplementedException();
|
|
|
|
public virtual Task<string[]> ScanAsync(string path, CancellationToken cancellationToken)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<string[]> ScanAsync(Uri uri, CancellationToken cancellationToken)
|
|
{
|
|
using var httpClient = new HttpClient();
|
|
await using var uriStream = await httpClient.GetStreamAsync(uri);
|
|
|
|
return await ScanAsync(uriStream, cancellationToken);
|
|
}
|
|
|
|
public async Task<string[]> ScanAsync(IFormFile file, CancellationToken cancellationToken)
|
|
{
|
|
await using var fileStream = file.OpenReadStream();
|
|
|
|
return await ScanAsync(fileStream, cancellationToken);
|
|
}
|
|
|
|
public async Task<string[]> ScanAsync(Stream stream, CancellationToken cancellationToken)
|
|
{
|
|
var tempFile = Path.GetTempFileName();
|
|
|
|
try
|
|
{
|
|
await using (var tempFileStream = File.OpenWrite(tempFile))
|
|
await stream.CopyToAsync(tempFileStream, cancellationToken);
|
|
|
|
return await ScanAsync(tempFile, cancellationToken);
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(tempFile);
|
|
}
|
|
}
|
|
}
|
|
} |