From 0bf016d0ff500a2a2ffc51a22f90748b79d6dbbc Mon Sep 17 00:00:00 2001 From: Mark Linton Date: Sun, 10 Nov 2013 10:11:42 -0800 Subject: Expose Rar support --- .../Archiving/ZipClient.cs | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'MediaBrowser.Common.Implementations/Archiving/ZipClient.cs') 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); + } + } + } } } -- cgit v1.2.3