mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
initial support for Archive API for 7z files
This commit is contained in:
parent
5f15f72dc7
commit
ab92f0bcda
2 changed files with 12 additions and 25 deletions
|
|
@ -64,11 +64,6 @@ public Handler(AgentHttpClient httpClient)
|
|||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
await DownloadByFileExtension(request, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task DownloadByFileExtension(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
|
||||
{
|
||||
|
|
@ -77,14 +72,12 @@ private async Task DownloadByFileExtension(Command request, CancellationToken ca
|
|||
{
|
||||
var sourceExtension = Path.GetExtension(request.ListInfo.ViewUrl.AbsolutePath);
|
||||
string destinationExtension;
|
||||
if (string.IsNullOrEmpty(sourceExtension) || sourceExtension == ".zip" ||
|
||||
sourceExtension == ".7z")
|
||||
if (string.IsNullOrEmpty(sourceExtension) || sourceExtension == ".zip" || sourceExtension == ".7z")
|
||||
destinationExtension = ".txt";
|
||||
else
|
||||
destinationExtension = sourceExtension;
|
||||
|
||||
using (var output = File.OpenWrite(Path.Combine("archives",
|
||||
$"{request.ListInfo.Id}{destinationExtension}")))
|
||||
using (var output = File.OpenWrite(Path.Combine("archives", $"{request.ListInfo.Id}{destinationExtension}")))
|
||||
{
|
||||
switch (DownloadRequestsByFileExtension[sourceExtension])
|
||||
{
|
||||
|
|
@ -95,7 +88,7 @@ private async Task DownloadByFileExtension(Command request, CancellationToken ca
|
|||
await input.CopyToWithCompressedReaderApi(output, cancellationToken);
|
||||
break;
|
||||
case FileType.NonForwardOnlyCompressed:
|
||||
await input.CopyToWithCompressedArchiveApi(output, cancellationToken);
|
||||
input.CopyToWithCompressedArchiveApi(output);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Archives.SevenZip;
|
||||
using SharpCompress.Readers;
|
||||
|
||||
namespace FilterLists.Agent.ListArchiver
|
||||
|
|
@ -34,19 +33,14 @@ public static async Task CopyToWithCompressedReaderApi(this Stream input, Stream
|
|||
/// e.g. 7zip
|
||||
/// https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md
|
||||
/// </summary>
|
||||
public static async Task CopyToWithCompressedArchiveApi(this Stream input, Stream output,
|
||||
CancellationToken cancellationToken)
|
||||
public static void CopyToWithCompressedArchiveApi(this Stream input, Stream output)
|
||||
{
|
||||
//var archive = ArchiveFactory.Open(@"C:\Code\sharpcompress\TestArchives\sharpcompress.zip");
|
||||
//foreach (var entry in archive.Entries)
|
||||
// if (!entry.IsDirectory)
|
||||
// {
|
||||
// Console.WriteLine(entry.Key);
|
||||
// entry.WriteToDirectory(@"C:\temp",
|
||||
// new ExtractionOptions {ExtractFullPath = true, Overwrite = true});
|
||||
// }
|
||||
|
||||
throw new NotImplementedException();
|
||||
using (var archive = SevenZipArchive.Open(input))
|
||||
{
|
||||
foreach (var entry in archive.Entries)
|
||||
if (!entry.IsDirectory)
|
||||
entry.WriteTo(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue