A managed wrapper (and then some) around libzip (https://libzip.org/)
Перейти к файлу
Marek Habersack 57558e9e9b
Bump zlib-ng to v2.2.2 (#147)
Changes: https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.2

Fixes a data corruption bug when decompressing very large files,
so most likely not a big issue for us.  Update regardless.
2024-09-20 18:28:38 +00:00
.gdn
.vscode
LibZipSharp Bump libzip to 1.11.1 (#146) 2024-09-20 15:34:26 +01:00
LibZipSharp.UnitTest
Localize
ZipBenchmark Give zlib-ng another chance (#145) 2024-07-05 15:36:54 +00:00
ZipTest
build-tools/prep
data
docs
external Bump zlib-ng to v2.2.2 (#147) 2024-09-20 18:28:38 +00:00
native
yaml-templates
.editorconfig
.gitattributes
.gitignore Give zlib-ng another chance (#145) 2024-07-05 15:36:54 +00:00
.gitmodules
CMakeLists.txt Give zlib-ng another chance (#145) 2024-07-05 15:36:54 +00:00
CODE-OF-CONDUCT.md Link Code of Conduct (#144) 2024-06-13 15:08:41 +00:00
LICENSE
LibZipSharp.code-workspace
LibZipSharp.props Bump libzip to 1.11.1 (#146) 2024-09-20 15:34:26 +01:00
NuGet.Config
README.md
SignList.xml
azure-pipelines.yml Bump libzip to 1.11.1 (#146) 2024-09-20 15:34:26 +01:00
build.sh Give zlib-ng another chance (#145) 2024-07-05 15:36:54 +00:00
build_windows.bat
global.json
libZipSharp.sln

README.md

LibZipSharp

A managed wrapper (and then some) around libzip (https://libzip.org/)

Build Status

The core of LibZipSharp is the ZipArchive class. You can use this class to create/extract/update zip file.

Create a new Zip

To create a new archive use the FileMode.CreateNew, this will behave exactly as it does with normal File operations. An exception will be thrown if the file already exists.

using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) {
}

Open am existing Zip

To open an existing zip file use FileMode.Open.

using (var zip = ZipArchive.Open ("test.zip", FileMode.Open)) {
}

Add files to Zip

There are a number of methods which can be used to add items to the zip file. The simplest is AddFile. This takes a file path. If filename is an absolute path, it will be converted to a relative one by removing the root of the path (i.e. the leading / part on Unix systems and the x:\\ part on Windows). You can also pass an archivePath parameter where you can specify the name/path which file will have within the archive.

using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) {
    zip.AddFile ("somefile.txt");
}

You can also add data directly from a MemoryStream via the AddEntry method. This takes an entryName and a MemoryStream. Note the MemoryStream will be disposed of when the zip file is finally written to disk.

var ms = new MemoryStream ();
// write data to stream.
using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) {
    zip.AddEntry ("foo", ms);
}

You can also add text directly via the AddEntry method. This method takes an entryName and text parameters. The entryName defines what the item in the zip file will be called. The text defines the contents on the entry. There is also an encoding parameter where you can define the Encoding of the file.

using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) {
    zip.AddEntry ("foo", "contents of the file", Encoding.UTF8);
}

Shipping the native libraries.

By default the native libraries will NOT be copied into the output directory of your app. .Net Core apps will pick these files up automatically. However for Mono you will need the libzip.* files in the same directory as the final app for this library to work. Setting the LibZipSharpBundleAllNativeLibraries MSBuild property to true will make sure the native libraries for ALL supported platforms are copied to the output directory.

You can do this via the command line

/p:LibZipSharpBundleAllNativeLibraries=True

or by adding the following to you csproj.

<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>