From 0bf016d0ff500a2a2ffc51a22f90748b79d6dbbc Mon Sep 17 00:00:00 2001 From: Mark Linton Date: Sun, 10 Nov 2013 10:11:42 -0800 Subject: [PATCH] Expose Rar support --- .../Archiving/ZipClient.cs | 39 +++++++++++++++++++ MediaBrowser.Model/IO/IZipClient.cs | 16 ++++++++ 2 files changed, 55 insertions(+) diff --git a/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs b/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs index 2b66617af..23d40cf67 100644 --- a/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs +++ b/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs @@ -1,4 +1,5 @@ using MediaBrowser.Model.IO; +using SharpCompress.Archive.Rar; using SharpCompress.Archive.SevenZip; using SharpCompress.Archive.Tar; using SharpCompress.Common; @@ -123,5 +124,43 @@ namespace MediaBrowser.Common.Implementations.Archiving } } } + + /// + /// Extracts all from rar. + /// + /// The source file. + /// The target path. + /// if set to true [overwrite existing files]. + public void ExtractAllFromRar(string sourceFile, string targetPath, bool overwriteExistingFiles) + { + using (var fileStream = File.OpenRead(sourceFile)) + { + ExtractAllFromRar(fileStream, targetPath, overwriteExistingFiles); + } + } + + /// + /// Extracts all from rar. + /// + /// The source. + /// The target path. + /// if set to true [overwrite existing files]. + public void ExtractAllFromRar(Stream source, string targetPath, bool overwriteExistingFiles) + { + using (var archive = RarArchive.Open(source)) + { + using (var reader = archive.ExtractAllEntries()) + { + var options = ExtractOptions.ExtractFullPath; + + if (overwriteExistingFiles) + { + options = options | ExtractOptions.Overwrite; + } + + reader.WriteAllToDirectory(targetPath, options); + } + } + } } } diff --git a/MediaBrowser.Model/IO/IZipClient.cs b/MediaBrowser.Model/IO/IZipClient.cs index 1fa3e0271..ba0725da5 100644 --- a/MediaBrowser.Model/IO/IZipClient.cs +++ b/MediaBrowser.Model/IO/IZipClient.cs @@ -54,5 +54,21 @@ namespace MediaBrowser.Model.IO /// The target path. /// if set to true [overwrite existing files]. void ExtractAllFromTar(Stream source, string targetPath, bool overwriteExistingFiles); + + /// + /// Extracts all from rar. + /// + /// The source file. + /// The target path. + /// if set to true [overwrite existing files]. + void ExtractAllFromRar(string sourceFile, string targetPath, bool overwriteExistingFiles); + + /// + /// Extracts all from rar. + /// + /// The source. + /// The target path. + /// if set to true [overwrite existing files]. + void ExtractAllFromRar(Stream source, string targetPath, bool overwriteExistingFiles); } }