Cube.FileSystem.SevenZip 1.15.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cube.FileSystem.SevenZip --version 1.15.10                
NuGet\Install-Package Cube.FileSystem.SevenZip -Version 1.15.10                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cube.FileSystem.SevenZip" Version="1.15.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cube.FileSystem.SevenZip --version 1.15.10                
#r "nuget: Cube.FileSystem.SevenZip, 1.15.10"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Cube.FileSystem.SevenZip as a Cake Addin
#addin nuget:?package=Cube.FileSystem.SevenZip&version=1.15.10

// Install Cube.FileSystem.SevenZip as a Cake Tool
#tool nuget:?package=Cube.FileSystem.SevenZip&version=1.15.10                

NuGet AppVeyor Codecov

Cube.FileSystem.SevenZip is a wrapper library of the 7-Zip via 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 later.

Usage

You can install the library through the NuGet package. Add a dependency in your project file using the following syntax:

<ItemGroup>
    <PackageReference Include="Cube.FileSystem.SevenZip" Version="1.15.10" />
</ItemGroup>

Or select it from the NuGet packages UI on Visual Studio.

Examples for archiving files

A simple example for archiving files is as follows. Note that 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

References

Cube.FileSystem.SevenZip referred to the code of the following projects to implement some functions.

Contributing

  1. Fork Cube.FileSystem.SevenZip repository.
  2. Create a feature branch from the master or stable branch (e.g. git checkout -b my-new-feature origin/master). Note that the master branch may refer some pre-released NuGet packages. Try the rake clean command when build errors occur.
  3. Commit your changes.
  4. Rebase your local changes against the master or stable branch.
  5. Run the dotnet test command or the Visual Studio (NUnit 3 test adapter) and confirm that it passes.
  6. Create new Pull Request.

License

Copyright © 2010 CubeSoft, Inc. The project is licensed under the Apache 2.0. Note that trade names, trademarks, service marks, or logo images distributed in CubeSoft applications are not allowed to reuse or modify all or parts of them.

Product Compatible and additional computed target framework versions.
.NET Framework net35 is compatible.  net40 was computed.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.4.1 136 5/29/2024
7.0.0 1,005 7/21/2022
6.0.1 930 3/1/2022
6.0.0 920 1/24/2022
5.0.0 826 10/26/2021
1.15.10 1,021 6/15/2020
1.15.0 1,218 4/22/2019
1.14.0 1,163 2/17/2019
1.13.0 1,218 11/22/2018
1.12.0 1,214 10/23/2018
1.11.1 1,235 10/17/2018
1.11.0 1,258 10/17/2018