Convert RAR to ZIP via C#

Contents
[ Hide Show ]

If you want to convert RAR archive to ZIP read this article.

Convertation

Aspose.ZIP API provides  RarArchive class to extract RAR archives. We can extract an entry to memory without saving it into intermediate storage and pass into ZIP archive right away.

Make sure you have enough virtual memory to keep content of all entries.

Transfer an Entry

The following code example demonstrates how to extract entries from RAR archive and immediately put it to ZIP archive. Entries that are directories added with appended slash to specify their kind.

 1    using (Archive zip = new Archive())
 2    {
 3        using (RarArchive rar = new RarArchive(@"D:\archvie.rar"))
 4        {
 5            for (int i = 0; i < rar.Entries.Count; i++)
 6            {                        
 7                if (!rar.Entries[i].IsDirectory)
 8                {
 9                    var ms = new MemoryStream();
10                    rar.Entries[i].Extract(ms);
11                    ms.Seek(0, SeekOrigin.Begin);
12                    zip.CreateEntry(rar.Entries[i].Name, ms);
13                }
14                else
15                    zip.CreateEntry(rar.Entries[i].Name + "/", Stream.Null);
16            }
17        }
18
19        zip.Save("output.zip");
20    }
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.