Learn how to convert a RAR file to ZIP in C#: https://blog.aspose.com/2022/01/14/convert-rar-files-to-zip-in-csharp/
Last active
January 14, 2022 09:51
-
-
Save aspose-com-gists/9d4019d37d8b0b33d7e992bf09ace706 to your computer and use it in GitHub Desktop.
Convert RAR Files to ZIP in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Archive class for ZIP archive | |
using (Archive zip = new Archive()) | |
{ | |
// Load the RAR archive | |
using (RarArchive rar = new RarArchive(@"D:\archvie.rar")) | |
{ | |
// Loop through entries of RAR file | |
for (int i = 0; i < rar.Entries.Count; i++) | |
{ | |
// Copy each entry from RAR to ZIP | |
if (!rar.Entries[i].IsDirectory) | |
{ | |
var ms = new MemoryStream(); | |
rar.Entries[i].Extract(ms); | |
ms.Seek(0, SeekOrigin.Begin); | |
zip.CreateEntry(rar.Entries[i].Name, ms); | |
} | |
else | |
zip.CreateEntry(rar.Entries[i].Name + "/", Stream.Null); | |
} | |
} | |
// Save the resultant ZIP archive | |
zip.Save("output.zip"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment