mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
re-add initial support for 7zip
This commit is contained in:
parent
4c436d031e
commit
f9981094f4
2 changed files with 54 additions and 46 deletions
54
src/FilterLists.Agent/Features/Archiver/DownloadSevenZip.cs
Normal file
54
src/FilterLists.Agent/Features/Archiver/DownloadSevenZip.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.Entities;
|
||||
using FilterLists.Agent.Infrastructure.Clients;
|
||||
using MediatR;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.SevenZip;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public static class DownloadSevenZip
|
||||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
public Command(ListInfo listInfo)
|
||||
{
|
||||
ListInfo = listInfo;
|
||||
}
|
||||
|
||||
public ListInfo ListInfo { get; }
|
||||
}
|
||||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private const string RepoDirectory = @"archives";
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public Handler(AgentHttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient.Client;
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
using (var input = await response.Content.ReadAsStreamAsync())
|
||||
using (var archive = SevenZipArchive.Open(input))
|
||||
{
|
||||
foreach (var entry in archive.Entries)
|
||||
if (!entry.IsDirectory)
|
||||
entry.WriteToDirectory(destinationDirectoryPath,
|
||||
new ExtractionOptions {ExtractFullPath = true, Overwrite = true});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
//using System.IO;
|
||||
//using System.Threading;
|
||||
//using System.Threading.Tasks;
|
||||
//using SharpCompress.Archives;
|
||||
//using SharpCompress.Archives.SevenZip;
|
||||
//using SharpCompress.Readers;
|
||||
|
||||
//namespace FilterLists.Agent.Features.Archiver
|
||||
//{
|
||||
// public static class StreamExtensions
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// Downloads compressed streams that support forward-only reading.
|
||||
// /// e.g. Zip, GZip, BZip2, Tar, Rar, LZip, XZ
|
||||
// /// https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md
|
||||
// /// </summary>
|
||||
// public static async Task CopyToWithCompressedReaderApi(this Stream input, Stream output,
|
||||
// CancellationToken cancellationToken)
|
||||
// {
|
||||
// using (var reader = ReaderFactory.Open(input))
|
||||
// {
|
||||
// while (reader.MoveToNextEntry())
|
||||
// if (!reader.Entry.IsDirectory)
|
||||
// using (var entryStream = reader.OpenEntryStream())
|
||||
// {
|
||||
// await entryStream.CopyToAsync(output, cancellationToken);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Downloads compressed streams that only support the Archive API.
|
||||
// /// e.g. 7zip
|
||||
// /// https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md
|
||||
// /// </summary>
|
||||
// public static void CopyToWithCompressedArchiveApi(this Stream input, Stream output)
|
||||
// {
|
||||
// using (var archive = SevenZipArchive.Open(input))
|
||||
// {
|
||||
// foreach (var entry in archive.Entries)
|
||||
// if (!entry.IsDirectory)
|
||||
// entry.WriteTo(output);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Loading…
Reference in a new issue