2019-01-13 20:54:44 +01:00
|
|
|
using System.IO;
|
2016-10-28 20:35:17 +02:00
|
|
|
using MediaBrowser.Model.IO;
|
2018-09-12 19:26:21 +02:00
|
|
|
using SharpCompress.Common;
|
2016-11-11 05:25:21 +01:00
|
|
|
using SharpCompress.Readers;
|
2017-09-25 07:06:15 +02:00
|
|
|
using SharpCompress.Readers.GZip;
|
2013-09-25 02:54:51 +02:00
|
|
|
|
2017-08-16 08:43:41 +02:00
|
|
|
namespace Emby.Server.Implementations.Archiving
|
2013-09-25 02:54:51 +02:00
|
|
|
{
|
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Class DotNetZipClient.
|
2013-09-25 02:54:51 +02:00
|
|
|
/// </summary>
|
|
|
|
public class ZipClient : IZipClient
|
|
|
|
{
|
2020-04-14 21:16:04 +02:00
|
|
|
/// <inheritdoc />
|
2017-09-25 07:06:15 +02:00
|
|
|
public void ExtractAllFromGz(Stream source, string targetPath, bool overwriteExistingFiles)
|
|
|
|
{
|
2020-04-14 21:16:04 +02:00
|
|
|
using var reader = GZipReader.Open(source);
|
|
|
|
var options = new ExtractionOptions
|
2017-09-25 07:06:15 +02:00
|
|
|
{
|
2020-04-14 21:16:04 +02:00
|
|
|
ExtractFullPath = true,
|
|
|
|
Overwrite = overwriteExistingFiles
|
|
|
|
};
|
2017-09-25 07:06:15 +02:00
|
|
|
|
2021-09-27 00:23:43 +02:00
|
|
|
Directory.CreateDirectory(targetPath);
|
2020-04-14 21:16:04 +02:00
|
|
|
reader.WriteAllToDirectory(targetPath, options);
|
2017-09-25 07:06:15 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 21:16:04 +02:00
|
|
|
/// <inheritdoc />
|
2017-12-03 23:11:04 +01:00
|
|
|
public void ExtractFirstFileFromGz(Stream source, string targetPath, string defaultFileName)
|
|
|
|
{
|
2020-04-14 21:16:04 +02:00
|
|
|
using var reader = GZipReader.Open(source);
|
|
|
|
if (reader.MoveToNextEntry())
|
2017-12-03 23:11:04 +01:00
|
|
|
{
|
2020-04-14 21:16:04 +02:00
|
|
|
var entry = reader.Entry;
|
|
|
|
|
|
|
|
var filename = entry.Key;
|
|
|
|
if (string.IsNullOrWhiteSpace(filename))
|
2017-12-03 23:11:04 +01:00
|
|
|
{
|
2020-04-14 21:16:04 +02:00
|
|
|
filename = defaultFileName;
|
2017-12-03 23:11:04 +01:00
|
|
|
}
|
2020-04-14 21:16:04 +02:00
|
|
|
|
|
|
|
reader.WriteEntryToFile(Path.Combine(targetPath, filename));
|
2017-12-03 23:11:04 +01:00
|
|
|
}
|
|
|
|
}
|
2013-09-25 02:54:51 +02:00
|
|
|
}
|
|
|
|
}
|