RAR Extractor for .NET
Introduction to RAR Extractor for .NET
The RAR Extractor is a .NET library that allows developers to extract files from RAR archives. This guide provides an overview of the features and functionality of the RAR Extractor, along with code examples to get you started.
Extracting RAR Archives
To extract a RAR archive, you can use the ExtractToDirectory
method of the RarArchive
class. This method takes the path to the destination directory where the extracted files will be saved.
using (var extractor = new RarArchive("example.rar"))
{
extractor.ExtractToDirectory("extracted");
}
Extracting Specific Files from a RAR Archive
If you want to extract specific files from a RAR archive, you can use the Entries
property.
using (RarArchive archive = new RarArchive("archive.rar"))
{
using (var destination = File.Create(dataDir + "firstEntry.txt"))
{
using (var source = archive.Entries[0].Open())
{
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
destination.Write(buffer, 0, bytesRead);
}
}
}