Cube.FileSystem.SevenZip
7.0.0
Install-Package Cube.FileSystem.SevenZip -Version 7.0.0
dotnet add package Cube.FileSystem.SevenZip --version 7.0.0
<PackageReference Include="Cube.FileSystem.SevenZip" Version="7.0.0" />
paket add Cube.FileSystem.SevenZip --version 7.0.0
#r "nuget: Cube.FileSystem.SevenZip, 7.0.0"
// Install Cube.FileSystem.SevenZip as a Cake Addin
#addin nuget:?package=Cube.FileSystem.SevenZip&version=7.0.0
// Install Cube.FileSystem.SevenZip as a Cake Tool
#tool nuget:?package=Cube.FileSystem.SevenZip&version=7.0.0
Cube.FileSystem.SevenZip
Cube.FileSystem.SevenZip is a wrapper library of the 7-Zip via COM interface. The project also has an application for compressing or extracting archives, which name is CubeICE. Libraries and applications are available for .NET Framework 3.5, 4.5 or later. Note that some projects are licensed under the GNU LGPLv3 and the others under the Apache 2.0. See License.md for more information.
Usage
You can install the library through the NuGet package. Add dependencies in your project file 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.
// Set only what you need.
var files = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };
var options = new CompressionOption
{
CompressionLevel = CompressionLevel.Ultra,
CompressionMethod = CompressionMethod.Lzma,
EncryptionMethod = EncryptionMethod.Aes256,
Password = "password",
Filter = Filter.From(files),
CodePage = CodePage.Utf8,
};
using (var writer = new ArchiveWriter(Format.Zip, options))
{
writer.Add(@"path\to\file");
writer.Add(@"path\to\directory_including_files");
var progress = new Progress<Report>(e => DoSomething(e));
writer.Save(@"path\to\save.zip", 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.
var options = new CompressionOption
{
CompressionLevel = CompressionLevel.Ultra,
CompressionMethod = CompressionMethod.BZip2, // GZip, BZip2, XZ or Copy
};
using (var writer = new ArchiveWriter(Format.Tar, options))
{
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;
});
// Supports only the Filter property
var files = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };
var options = new ArchiveOption { Filter = Filter.From(files) };
using (var reader = new ArchiveReader(@"path\to\archive", password, options))
{
var progress = new Progress<Report>(e => DoSomething(e));
reader.Save(@"path\to\directory", progress);
}
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
- 7-Zip ... Cube.Native.SevenZip is optimized for Japanese encoding.
- AlphaFS ... Cube.FileSystem.AlphaFS is a wrapper library for using AlphaFS in Cube projects.
Contributing
- Fork Cube.FileSystem.SevenZip repository.
- Create a feature branch from the master (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.
- Commit your changes.
- Rebase your local changes against the master branch.
- Run the dotnet test command or the Visual Studio (NUnit 3 test adapter) and confirm that it passes.
- Create new Pull Request.
License
Copyright © 2010 CubeSoft, Inc. See License.md for more information.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETFramework 3.5
- Cube.Core (>= 7.0.0)
- Cube.Native.SevenZip (>= 22.0.1)
-
.NETFramework 4.7
- Cube.Core (>= 7.0.0)
- Cube.Native.SevenZip (>= 22.0.1)
-
.NETStandard 2.0
- Cube.Core (>= 7.0.0)
- Cube.Native.SevenZip (>= 22.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.