Cube.FileSystem.SevenZip 1.12.0

Archive library to wrap 7-Zip in .NET Framework.

Install-Package Cube.FileSystem.SevenZip -Version 1.12.0
dotnet add package Cube.FileSystem.SevenZip --version 1.12.0
paket add Cube.FileSystem.SevenZip --version 1.12.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AppVeyor Codecov

Cube.FileSystem.SevenZip projects wrap the 7-Zip library through the COM interface. The repository also has an archiving or extracting application, which name is CubeICE. These libraries and applications are available for .NET Framework 3.5, 4.5 or more.

Usage

The Cube.FileSystem.SevenZip library is available for NuGet, but you need to copy the 7z.dll to the executing directory manually. You can download the library from www.7-zip.org or our GitHub releases.

Examples for archiving files

A simple example for archiving files is as follows. The statement "using Cube.FileSystem.SevenZip;" has been omitted in all samples.

using (var writer = new ArchiveWriter(Format.Zip))
{
    writer.Add(@"path\to\file");
    writer.Add(@"path\to\directory_including_files");
    writer.Option  = new ZipOption { CompressionLevel = CompressionLevel.Ultra };
    writer.Filters = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };
    
    var progress = new Progress<Report>(e => DoSomething(e));
    writer.Save(@"path\to\save.zip", "password", progress);
}

You create an ArchiveWriter object with an archiving format (e.g. Zip, SevenZip, ...), add files and/or directories you want to archive, set some additional options, and finally call the Save method. When you create Tar based archives, you can use a TarOption object for selecting a compression method.

using (var writer = new ArchiveWriter(Format.Tar))
{
    writer.Option = new TarOption
    {
        CompressionMethod = CompressionMethod.BZip2, // GZip, BZip2, XZ or Copy
        CompressionLevel  = CompressionLevel.Ultra,
    };

    writer.Add(@"path\to\file");
    writer.Add(@"path\to\directory_including_files");
    writer.Save(@"path\to\save.tar.gz");
}

Examples for extracting archives

If you want to extract all files from the archive, you create an ArchiveReader object and call the Extract method. The 2nd argument of the constructor, that means the password of the archive, can be set string or Cube.Query<string> object. The latter is mainly used for implementing the interactive mode.

// Set password directly or using Query<string>
var password = new Cube.Query<string>(e =>
{
    e.Result = "password";
    e.Cancel = false;
});

using (var reader = new ArchiveReader(@"path\to\archive", password))
{
    var progress = new Progress<Report>(e => DoSomething(e));
    reader.Filters = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };    
    reader.Extract(@"path\to\directory", progress);
}

ArchvieReader.Items property can access each item of the archive. If you want to extract only the specific files, write as follows.

using (var reader = new ArchiveReader(@"path\to\archive", "password"))
{
    // Save as "path\to\directory\{item.FullName}"
    var directory = @"path\to\directory";
    reader.Items[0].Extract(directory);
    reader.Items[3].Extract(directory);
}

Note that ArchiveWriter and ArchiveReader classes need to execute in the same thread from constructing to destroying. Use Task.Run() in the whole transaction if you need to archive or extract files asynchronously.

Dependencies

Thanks

Contributing

  1. Fork Cube.FileSystem.SevenZip repository.
  2. Create a feature branch from the stable branch (git checkout -b my-new-feature origin/stable). The master branch may refer some pre-released NuGet packages. See AppVeyor.yml if you want to build and commit in the master branch.
  3. Commit your changes.
  4. Rebase your local changes against the stable (or master) branch.
  5. Run test suite with the NUnit console or the Visual Studio (NUnit 3 test adapter) and confirm that it passes.
  6. Create new Pull Request.

License

Copyright (c) 2010 CubeSoft, Inc. The Cube.FileSystem.SevenZip project is licensed under the GNU LGPLv3.

AppVeyor Codecov

Cube.FileSystem.SevenZip projects wrap the 7-Zip library through the COM interface. The repository also has an archiving or extracting application, which name is CubeICE. These libraries and applications are available for .NET Framework 3.5, 4.5 or more.

Usage

The Cube.FileSystem.SevenZip library is available for NuGet, but you need to copy the 7z.dll to the executing directory manually. You can download the library from www.7-zip.org or our GitHub releases.

Examples for archiving files

A simple example for archiving files is as follows. The statement "using Cube.FileSystem.SevenZip;" has been omitted in all samples.

using (var writer = new ArchiveWriter(Format.Zip))
{
    writer.Add(@"path\to\file");
    writer.Add(@"path\to\directory_including_files");
    writer.Option  = new ZipOption { CompressionLevel = CompressionLevel.Ultra };
    writer.Filters = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };
    
    var progress = new Progress<Report>(e => DoSomething(e));
    writer.Save(@"path\to\save.zip", "password", progress);
}

You create an ArchiveWriter object with an archiving format (e.g. Zip, SevenZip, ...), add files and/or directories you want to archive, set some additional options, and finally call the Save method. When you create Tar based archives, you can use a TarOption object for selecting a compression method.

using (var writer = new ArchiveWriter(Format.Tar))
{
    writer.Option = new TarOption
    {
        CompressionMethod = CompressionMethod.BZip2, // GZip, BZip2, XZ or Copy
        CompressionLevel  = CompressionLevel.Ultra,
    };

    writer.Add(@"path\to\file");
    writer.Add(@"path\to\directory_including_files");
    writer.Save(@"path\to\save.tar.gz");
}

Examples for extracting archives

If you want to extract all files from the archive, you create an ArchiveReader object and call the Extract method. The 2nd argument of the constructor, that means the password of the archive, can be set string or Cube.Query<string> object. The latter is mainly used for implementing the interactive mode.

// Set password directly or using Query<string>
var password = new Cube.Query<string>(e =>
{
    e.Result = "password";
    e.Cancel = false;
});

using (var reader = new ArchiveReader(@"path\to\archive", password))
{
    var progress = new Progress<Report>(e => DoSomething(e));
    reader.Filters = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };    
    reader.Extract(@"path\to\directory", progress);
}

ArchvieReader.Items property can access each item of the archive. If you want to extract only the specific files, write as follows.

using (var reader = new ArchiveReader(@"path\to\archive", "password"))
{
    // Save as "path\to\directory\{item.FullName}"
    var directory = @"path\to\directory";
    reader.Items[0].Extract(directory);
    reader.Items[3].Extract(directory);
}

Note that ArchiveWriter and ArchiveReader classes need to execute in the same thread from constructing to destroying. Use Task.Run() in the whole transaction if you need to archive or extract files asynchronously.

Dependencies

Thanks

Contributing

  1. Fork Cube.FileSystem.SevenZip repository.
  2. Create a feature branch from the stable branch (git checkout -b my-new-feature origin/stable). The master branch may refer some pre-released NuGet packages. See AppVeyor.yml if you want to build and commit in the master branch.
  3. Commit your changes.
  4. Rebase your local changes against the stable (or master) branch.
  5. Run test suite with the NUnit console or the Visual Studio (NUnit 3 test adapter) and confirm that it passes.
  6. Create new Pull Request.

License

Copyright (c) 2010 CubeSoft, Inc. The Cube.FileSystem.SevenZip project is licensed under the GNU LGPLv3.

Version History

Version Downloads Last updated
1.12.0 34 10/23/2018
1.11.1 39 10/17/2018
1.11.0 36 10/17/2018