using MediaBrowser.Model.IO;
using SharpCompress.Archive.SevenZip;
using SharpCompress.Common;
using SharpCompress.Reader;
using System.IO;
namespace MediaBrowser.Common.Implementations.Archiving
{
///
/// Class DotNetZipClient
///
public class ZipClient : IZipClient
{
///
/// Extracts all.
///
/// The source file.
/// The target path.
/// if set to true [overwrite existing files].
public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
{
using (var fileStream = File.OpenRead(sourceFile))
{
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
}
}
///
/// Extracts all.
///
/// The source.
/// The target path.
/// if set to true [overwrite existing files].
public void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles)
{
using (var reader = ReaderFactory.Open(source))
{
var options = ExtractOptions.ExtractFullPath;
if (overwriteExistingFiles)
{
options = options | ExtractOptions.Overwrite;
}
reader.WriteAllToDirectory(targetPath, options);
}
}
///
/// Extracts all from7z.
///
/// The source file.
/// The target path.
/// if set to true [overwrite existing files].
public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
{
using (var fileStream = File.OpenRead(sourceFile))
{
ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
}
}
///
/// Extracts all from7z.
///
/// The source.
/// The target path.
/// if set to true [overwrite existing files].
public void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles)
{
using (var archive = SevenZipArchive.Open(source))
{
using (var reader = archive.ExtractAllEntries())
{
var options = ExtractOptions.ExtractFullPath;
if (overwriteExistingFiles)
{
options = options | ExtractOptions.Overwrite;
}
reader.WriteAllToDirectory(targetPath, options);
}
}
}
}
}