-
Notifications
You must be signed in to change notification settings - Fork 481
API Examples
Matthias Fussenegger edited this page Apr 5, 2018
·
7 revisions
using (Stream stream = File.OpenRead(@"C:\Code\sharpcompress.rar"))
{
var reader = ReaderFactory.Open(stream);
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
Console.WriteLine(reader.Entry.Key);
reader.WriteEntryToDirectory(@"C:\temp", new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
}
}
}
var archive = ArchiveFactory.Open(@"C:\Code\sharpcompress\TestArchives\sharpcompress.zip");
foreach (var entry in archive.Entries)
{
if (!entry.IsDirectory)
{
Console.WriteLine(entry.Key);
entry.WriteToDirectory(@"C:\temp", new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
}
}
using (var archive = ZipArchive.Create())
{
archive.AddAllFromDirectory(@"C:\source");
archive.SaveTo(@"C:\new.zip");
}
using (var zip = File.OpenWrite("C:\\test.zip"))
using (var zipWriter = WriterFactory.Open(zip, ArchiveType.Zip, CompressionType.Deflate))
{
foreach (var filePath in filesList)
{
zipWriter.Write(Path.GetFileName(file), filePath);
}
}
using (Stream stream = File.OpenWrite(tarbz2Path))
using (var writer = WriterFactory.Open(stream, ArchiveType.Tar, CompressionType.BZip2))
{
writer.WriteAll(filesPath, "*", SearchOption.AllDirectories);
}