├── LibZipSharp.UnitTest ├── characters_players.json ├── packaged_resources ├── info.json ├── object_spawn.json ├── ZipWrapper.cs └── LibZipSharp.UnitTest.csproj ├── LibZipSharp ├── product.snk ├── Xamarin.Tools.Zip │ ├── Constants.cs.in │ ├── Info.cs │ ├── Versions.cs │ ├── IPlatformOptions.cs │ ├── WindowsPlatformOptions.cs │ ├── ZipHeaderLocation.cs │ ├── EntryExtractEventArgs.cs │ ├── UnixPlatformOptions.cs │ ├── ExtraField_UnixIDBase.cs │ ├── ZipEntry.Unix.cs │ ├── PlatformServices.Unix.cs │ ├── ArchiveGlobalFlags.cs │ ├── ErrorType.cs │ ├── ZipArchive.Unix.cs │ ├── WindowsZipEntry.cs │ ├── OpenFlags.cs │ ├── EntryPermissions.cs │ ├── UnixZipEntry.Unix.cs │ ├── WindowsZipArchive.cs │ ├── StatFlags.cs │ ├── ExtraField_InfoZipUnixType2.cs │ ├── UnixZipEntry.cs │ ├── UnixZipArchive.cs │ ├── ZipEntryEnumerator.cs │ ├── IPlatformServices.cs │ ├── ExtraField_InfoZipUnix3rdGeneration.cs │ ├── OperationFlags.cs │ ├── UnixExternalPermissions.cs │ ├── OperatingSystem.cs │ ├── ExtraField_InfoZipUnixOriginal.cs │ ├── SourceCommand.cs │ ├── CompressionMethod.cs │ ├── ZipIOException.cs │ ├── ExtraField.cs │ ├── ZipException.cs │ ├── EncryptionMethod.cs │ ├── ErrorCode.cs │ ├── Utilities.cs │ ├── PlatformServices.cs │ ├── Utilities.Unix.cs │ └── ExtraField_ExtendedTimestamp.cs ├── Xamarin.LibZipSharp.targets.in ├── libZipSharp.targets └── libZipSharp.csproj ├── LibZipSharp.code-workspace ├── global.json ├── .vscode ├── settings.json ├── extensions.json ├── launch.json └── tasks.json ├── .gdn ├── .gdnsettings ├── .gitignore └── .gdnsuppress ├── native ├── sizes.cc ├── sizes.hh ├── values.cc ├── helpers.hh ├── version.hh ├── values.hh └── version.cc ├── data └── bzip2.pc.in ├── CODE-OF-CONDUCT.md ├── SignList.xml ├── yaml-templates ├── variables.yml ├── use-dot-net.yaml ├── stage-test.yml └── stage-build.yml ├── Localize └── LocProject.json ├── azure-pipelines-public.yml ├── NuGet.Config ├── .gitmodules ├── .gitignore ├── .gitattributes ├── LICENSE ├── LibZipSharp.props ├── ZipBenchmark ├── Program.cs ├── ZipBenchmark.csproj └── Performance.cs ├── ZipTest ├── ZipTest.csproj └── Program.cs ├── README.md ├── libZipSharp.sln ├── docs └── timezone.txt └── .editorconfig /LibZipSharp.UnitTest/characters_players.json: -------------------------------------------------------------------------------- 1 | { 2 | "players": [] 3 | } -------------------------------------------------------------------------------- /LibZipSharp/product.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/android-libzipsharp/HEAD/LibZipSharp/product.snk -------------------------------------------------------------------------------- /LibZipSharp.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": {} 8 | } -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "msbuild-sdks": { 3 | "Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.25515.2" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /LibZipSharp.UnitTest/packaged_resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/android-libzipsharp/HEAD/LibZipSharp.UnitTest/packaged_resources -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "nxunitExplorer.modules": [ 3 | "LibZipSharp.UnitTest/bin/Debug/net471/LibZipSharp.UnitTest.dll", 4 | ] 5 | } -------------------------------------------------------------------------------- /.gdn/.gdnsettings: -------------------------------------------------------------------------------- 1 | { 2 | "files": { }, 3 | "folders": { }, 4 | "overwriteLogs": true, 5 | "telemetryFlushTimeout": 10, 6 | "variables": { } 7 | } 8 | -------------------------------------------------------------------------------- /.gdn/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Guardian internal files 2 | .r/ 3 | rc/ 4 | rs/ 5 | i/ 6 | p/ 7 | c/ 8 | o/ 9 | 10 | ## Ignore Guardian Local settings 11 | LocalSettings.gdn.json 12 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/Constants.cs.in: -------------------------------------------------------------------------------- 1 | namespace Xamarin.Tools.Zip 2 | { 3 | static class Constants 4 | { 5 | public const string ZIP_LIBNAME = "@LibraryBaseFileName@"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /native/sizes.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sizes.hh" 4 | 5 | uint64_t lzs_get_size_zip_source_args_seek () 6 | { 7 | return static_cast(sizeof (zip_source_args_seek_t)); 8 | } 9 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/Info.cs: -------------------------------------------------------------------------------- 1 | namespace Xamarin.Tools.Zip 2 | { 3 | public class Info 4 | { 5 | public static Versions GetVersions () 6 | { 7 | return Native.get_versions (); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /native/sizes.hh: -------------------------------------------------------------------------------- 1 | #if !defined (__LZS_SIZES_HH) 2 | #define __LZS_SIZES_HH 3 | 4 | #include "helpers.hh" 5 | 6 | extern "C" { 7 | LZS_API uint64_t lzs_get_size_zip_source_args_seek (); 8 | } 9 | #endif // __LZS_SIZES_HH 10 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-vscode.csharp", 4 | "ms-vscode.cpptools", 5 | "ms-vscode.mono-debug", 6 | "wghats.vscode-nxunit-test-adapter", 7 | "visualstudioexptteam.vscodeintellicode", 8 | ] 9 | } -------------------------------------------------------------------------------- /data/bzip2.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: bzip2 7 | Description: bzip2 8 | Version: 1.0.8 9 | Requires: 10 | Libs: ${libdir}/libbzip2.a 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project has adopted the code of conduct defined by the Contributor Covenant 4 | to clarify expected behavior in our community. 5 | 6 | For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). 7 | -------------------------------------------------------------------------------- /SignList.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /yaml-templates/variables.yml: -------------------------------------------------------------------------------- 1 | variables: 2 | - name: WindowsPoolImage1ESPT 3 | value: 1ESPT-Windows2022 4 | - name: LinuxPoolImage1ESPT 5 | value: 1ESPT-Ubuntu22.04 6 | - name: WindowsPoolImageHosted 7 | value: windows-2022 8 | - name: LinuxPoolImageHosted 9 | value: ubuntu-22.04 10 | - name: MicroBuildPoolName 11 | value: VSEngSS-MicroBuild2022-1ES 12 | -------------------------------------------------------------------------------- /native/values.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "values.hh" 4 | 5 | uint32_t lzs_convert_whence_value (int32_t whence) 6 | { 7 | switch (whence) { 8 | case SEEK_SET: 9 | return LZS_SEEK_SET; 10 | 11 | case SEEK_CUR: 12 | return LZS_SEEK_CUR; 13 | 14 | case SEEK_END: 15 | return LZS_SEEK_END; 16 | 17 | default: 18 | return LZS_SEEK_INVALID; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Localize/LocProject.json: -------------------------------------------------------------------------------- 1 | { 2 | "Projects": [ 3 | { 4 | "LanguageSet": "VS_Main_Languages", 5 | "LocItems": [ 6 | { 7 | "CopyOption": "LangIDOnName", 8 | "SourceFile": ".\\LibZipSharp\\Properties\\Resources.resx", 9 | "OutputPath": ".\\LibZipSharp\\Properties" 10 | } 11 | ] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /azure-pipelines-public.yml: -------------------------------------------------------------------------------- 1 | trigger: none 2 | 3 | pr: 4 | - '*' 5 | 6 | variables: 7 | - template: /yaml-templates/variables.yml 8 | 9 | stages: 10 | - template: /yaml-templates/stage-build.yml 11 | parameters: 12 | use1ESTemplate: false 13 | publishTaskPrefix: '' 14 | 15 | - template: /yaml-templates/stage-test.yml 16 | parameters: 17 | use1ESTemplate: false 18 | publishTaskPrefix: '' 19 | -------------------------------------------------------------------------------- /native/helpers.hh: -------------------------------------------------------------------------------- 1 | #if !defined (__LZS_HELPERS_HH) 2 | #define __LZS_HELPERS_HH 3 | 4 | #include 5 | #include 6 | 7 | #if defined(_MSC_VER) 8 | #define LZS_API __declspec(dllexport) 9 | #else 10 | #if defined (__clang__) || defined (__GNUC__) 11 | #define LZS_API __attribute__ ((__visibility__ ("default"))) 12 | #else 13 | #define LZS_API 14 | #endif 15 | #endif 16 | 17 | #endif // __LZS_HELPERS_HH 18 | -------------------------------------------------------------------------------- /native/version.hh: -------------------------------------------------------------------------------- 1 | #if !defined (__LZS_NATIVE_VERSION_HH) 2 | #define __LZS_NATIVE_VERSION_HH 3 | 4 | #include "helpers.hh" 5 | 6 | struct LZSVersions 7 | { 8 | const char *bzip2; 9 | const char *libzip; 10 | const char *zlib; 11 | const char *zlibng; 12 | const char *zstd; 13 | const char *libzipsharp; 14 | }; 15 | 16 | extern "C" { 17 | LZS_API void lzs_get_versions (LZSVersions *versions); 18 | } 19 | #endif // __LZS_NATIVE_VERSION_HH 20 | -------------------------------------------------------------------------------- /native/values.hh: -------------------------------------------------------------------------------- 1 | #if !defined (__LZS_VALUES_HH) 2 | #define __LZS_VALUES_HH 3 | 4 | #include "helpers.hh" 5 | 6 | // Values here must be identical to those in LibZipSharp/Xamarin.Tools.Zip/Native.cs 7 | constexpr uint32_t LZS_SEEK_SET = 0; 8 | constexpr uint32_t LZS_SEEK_CUR = 1; 9 | constexpr uint32_t LZS_SEEK_END = 2; 10 | constexpr uint32_t LZS_SEEK_INVALID = 0xDEADBEEF; 11 | 12 | extern "C" { 13 | LZS_API uint32_t lzs_convert_whence_value (int32_t whence); 14 | } 15 | #endif // __LZS_VALUES_HH 16 | -------------------------------------------------------------------------------- /LibZipSharp.UnitTest/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 22, 3 | "type": "Object", 4 | "id": "c9bb1a03-cb8a-4f9f-b298-49ee26fa1fd9", 5 | "ownerId": "47b9d124-6421-4055-abf4-b5fc8fbfe784", 6 | "name": "OBJECT NAME", 7 | "description": "", 8 | "blockCount": 9, 9 | "created": "2019-06-21T14:20:42.000Z", 10 | "lastChanged": "0001-01-01T00:00:00.000Z", 11 | "tags": [ 12 | { 13 | "value": "some_tag", 14 | "origin": "category" 15 | }, 16 | { 17 | "value": "some_other_tag", 18 | "origin": "category" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/Versions.cs: -------------------------------------------------------------------------------- 1 | namespace Xamarin.Tools.Zip 2 | { 3 | public class Versions 4 | { 5 | public string BZip2 { 6 | get; internal set; 7 | } 8 | 9 | public string LibZip { 10 | get; internal set; 11 | } 12 | 13 | public string Zlib { 14 | get; internal set; 15 | } 16 | 17 | public string ZStd { 18 | get; internal set; 19 | } 20 | 21 | public string ZlibNG { 22 | get; internal set; 23 | } 24 | 25 | public string LibZipSharp { 26 | get; internal set; 27 | } 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LibZipSharp.UnitTest/object_spawn.json: -------------------------------------------------------------------------------- 1 | { 2 | "spawnRotationOffset": 3 | { 4 | "pitch": -16.274194717407227, 5 | "yaw": -34.644023895263672, 6 | "roll": 65.772232055664063 7 | }, 8 | "spawnScaleOffset": 9 | { 10 | "x": 0.52916890382766724, 11 | "y": 0.52916890382766724, 12 | "z": 0.52916890382766724 13 | }, 14 | "bounds": 15 | { 16 | "origin": 17 | { 18 | "x": -9086.74609375, 19 | "y": -6475.60498046875, 20 | "z": 1128.5997314453125 21 | }, 22 | "boxExtent": 23 | { 24 | "x": 400.17755126953125, 25 | "y": 474.9906005859375, 26 | "z": 502.65240478515625 27 | }, 28 | "sphereRadius": 530.2637939453125 29 | } 30 | } -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/libzip"] 2 | path = external/libzip 3 | url = https://github.com/nih-at/libzip.git 4 | [submodule "external/vcpkg"] 5 | path = external/vcpkg 6 | url = https://github.com/Microsoft/vcpkg 7 | [submodule "external/zlib-ng"] 8 | path = external/zlib-ng 9 | url = https://github.com/zlib-ng/zlib-ng.git 10 | branch = develop 11 | [submodule "external/bzip2"] 12 | path = external/bzip2 13 | url = https://sourceware.org/git/bzip2.git 14 | branch = master 15 | [submodule "zlib"] 16 | path = external/zlib 17 | url = https://github.com/madler/zlib.git 18 | branch = master 19 | [submodule "external/zstd"] 20 | path = external/zstd 21 | url = https://github.com/facebook/zstd.git 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Autosave files 2 | *~ 3 | 4 | #build 5 | [Oo]bj/ 6 | [Bb]in/ 7 | packages/ 8 | TestResults/ 9 | 10 | # globs 11 | Makefile.in 12 | *.DS_Store 13 | *.sln.cache 14 | *.suo 15 | *.cache 16 | *.pidb 17 | *.userprefs 18 | *.usertasks 19 | config.log 20 | config.make 21 | config.status 22 | aclocal.m4 23 | install-sh 24 | autom4te.cache/ 25 | *.user 26 | *.tar.gz 27 | tarballs/ 28 | test-results/ 29 | Thumbs.db 30 | 31 | #Mac bundle stuff 32 | *.dmg 33 | *.app 34 | 35 | #resharper 36 | *_Resharper.* 37 | *.Resharper 38 | 39 | #dotCover 40 | *.dotCover 41 | archives 42 | libZipSharp.dll.config 43 | libZipSharp.xml 44 | 45 | #VS 2017 46 | .vs/ 47 | 48 | build.log 49 | build/* 50 | *.nupkg 51 | TestResult.xml 52 | artifacts 53 | lzsbuild 54 | .ccls-cache 55 | ZipBenchmark/BenchmarkDotNet.Artifacts/ -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "mono", 10 | "request": "launch", 11 | "program": "~/.nuget/packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe ${workspaceRoot}LibZipSharp.UnitTest/bin/Debug/net471/LibZipSharp.UnitTest.dll", 12 | "cwd": "${workspaceRoot}bin/TestDebug/" 13 | }, 14 | { 15 | "name": "Attach", 16 | "type": "mono", 17 | "request": "attach", 18 | "address": "localhost", 19 | "port": 55555 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /native/version.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "version.hh" 8 | 9 | constexpr char libzipsharp_version[] = LIBZIPSHARP_VERSION; 10 | constexpr char libzip_version[] = LIBZIP_VERSION; 11 | constexpr char libzlib_version[] = ZLIB_VERSION; 12 | #if defined (ZLIBNG_VERSION) 13 | constexpr char libzlibng_version[] = ZLIBNG_VERSION; 14 | #else 15 | constexpr char libzlibng_version[] = "not used"; 16 | #endif // ndef ZLIBNG_VERSION 17 | 18 | void lzs_get_versions (LZSVersions *versions) 19 | { 20 | if (versions == nullptr) { 21 | return; 22 | } 23 | 24 | versions->bzip2 = strdup (BZ2_bzlibVersion ()); 25 | versions->libzip = strdup (libzip_version); 26 | versions->zlib = strdup (libzlib_version); 27 | versions->zlibng = strdup (libzlibng_version); 28 | versions->zstd = strdup (ZSTD_versionString ()); 29 | versions->libzipsharp = strdup (libzipsharp_version); 30 | } 31 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # NOTE: this file is for git 1.6.6 (and possibly older) 2 | # Post-1.7.2 there is eol and text, and crlf is deprecated 3 | # but we can't depend on an unreleased version... 4 | 5 | # This file mainly controls line ending conversion behaviour, if 6 | # the user has the setting core.autocrlf true. 7 | 8 | # The meaning of the attributes is a little odd 9 | # -crlf means DO NOT convert line endings 10 | # crlf means CONVERT to lf in the repo & Linux/Mac, crlf on Windows 11 | 12 | # sln is always CRLF, even on linux, so don't convert 13 | *.sln eol=crlf 14 | *.bat eol=crlf 15 | *.cmd eol=crlf 16 | *.rtf eol=crlf 17 | *.sh eol=lf 18 | 19 | # Mostly generated by VS, so avoid extra noise 20 | *.Designer.cs eol=crlf 21 | 22 | *.cs text 23 | *.xml text 24 | *.md text 25 | Makefile eol=lf 26 | *.targets eol=crlf 27 | *.proj eol=crlf 28 | *.vcproj eol=crlf 29 | *.vcxproj eol=crlf 30 | *.csproj eol=crlf 31 | *.shproj eol=crlf 32 | *.projitems eol=crlf 33 | *.wixproj eol=crlf 34 | *.wxs eol=crlf 35 | *.rtf eol=crlf 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Marek Habersack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LibZipSharp.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | <_LibZipSharpAssemblyVersionMajor>3 4 | <_LibZipSharpAssemblyVersionMinor>5 5 | <_LibZipSharpAssemblyVersionPatch>1 6 | <_LibZipSharpAssemblyVersion>$(_LibZipSharpAssemblyVersionMajor).$(_LibZipSharpAssemblyVersionMinor).$(_LibZipSharpAssemblyVersionPatch) 7 | <_NativeLibraryVersionForName>$(_LibZipSharpAssemblyVersionMajor)-$(_LibZipSharpAssemblyVersionMinor) 8 | <_NativeLibraryBaseName>libZipSharpNative-$(_NativeLibraryVersionForName) 9 | <_DotNetTargetFramework>net7.0 10 | 11 | 15 | <_LibZipSharpNugetVersion>$(_LibZipSharpAssemblyVersion) 16 | <_NativeBuildDir>$(MSBuildThisFileDirectory)lzsbuild 17 | <_ExternalDir>$(MSBuildThisFileDirectory)external 18 | <_MonoPosixNugetVersion>7.1.0-final.1.21458.1 19 | 20 | 21 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/IPlatformOptions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // IPlatformOptions.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | public interface IPlatformOptions 31 | { 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/WindowsPlatformOptions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // WindowsPlatformOptions.cs 3 | // 4 | // Author: 5 | // Dean Ellis 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | namespace Xamarin.Tools.Zip 28 | { 29 | public class WindowsPlatformOptions : IPlatformOptions 30 | { 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ZipHeaderLocation.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ExtraFieldLocation.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | public enum ZipHeaderLocation 31 | { 32 | Any, 33 | Local, 34 | Central, 35 | Both 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /ZipBenchmark/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | using BenchmarkDotNet.Attributes; 8 | using BenchmarkDotNet.Running; 9 | 10 | #if UNIX 11 | using Mono.Unix.Native; 12 | #endif 13 | using Xamarin.Tools.Zip; 14 | 15 | namespace ZipBenchmark; 16 | 17 | public class LargeFileCompression 18 | { 19 | // Fugly... 20 | public static string? InputFilePath; 21 | 22 | [Benchmark] 23 | [ArgumentsSource (nameof(Paths))] 24 | public void Compress (string inputFile) 25 | { 26 | string outputPath = $"{Path.GetFileName (inputFile)}.out.zip"; 27 | using (var zip = ZipArchive.Open (outputPath, FileMode.Create)) { 28 | zip.AddFile (inputFile); 29 | zip.Close (); 30 | } 31 | } 32 | 33 | public IEnumerable Paths () 34 | { 35 | if (String.IsNullOrEmpty (InputFilePath)) { 36 | throw new InvalidOperationException ("Input file path must be specified"); 37 | } 38 | 39 | yield return InputFilePath; 40 | } 41 | } 42 | 43 | class App 44 | { 45 | public static int Main (string [] args) 46 | { 47 | // if (args.Length == 0) { 48 | // Console.WriteLine ($"Usage: ZipBenchmark path/to/a/large/file/to/compress"); 49 | // Console.WriteLine (); 50 | // return 1; 51 | // } 52 | 53 | // LargeFileCompression.InputFilePath = args[0]; 54 | var summary = BenchmarkRunner.Run (); 55 | // Console.WriteLine ("Running..."); 56 | // Console.ReadLine (); 57 | // var p = new Performance (); 58 | // p.Setup (); 59 | // p.LibZipSharpCreateZip (); 60 | return 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/EntryExtractEventArgs.cs: -------------------------------------------------------------------------------- 1 | // 2 | // EntryExtractEventArgs.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | public class EntryExtractEventArgs : EventArgs 31 | { 32 | public ZipEntry Entry { get; internal set; } 33 | public ulong ProcessedSoFar { get; internal set; } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/UnixPlatformOptions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // UnixPlatformOptions.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | namespace Xamarin.Tools.Zip 28 | { 29 | public class UnixPlatformOptions : IPlatformOptions 30 | { 31 | public bool StoreSymlinks { get; set; } = true; 32 | 33 | public bool VerboseLogging { get; set; } = false; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /LibZipSharp.UnitTest/ZipWrapper.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | using System.Threading; 7 | using Xamarin.Tools.Zip; 8 | using Unix = Mono.Unix; 9 | 10 | namespace Tests { 11 | public class ZipWrapper : IDisposable { 12 | ZipArchive archive; 13 | string filename; 14 | public ZipArchive Archive => archive; 15 | 16 | public ZipWrapper (string file, FileMode mode = FileMode.CreateNew) { 17 | filename = file; 18 | archive = ZipArchive.Open (filename, mode); 19 | } 20 | 21 | public void Flush () { 22 | if (archive != null) { 23 | archive.Close (); 24 | archive.Dispose (); 25 | archive = null; 26 | } 27 | archive = ZipArchive.Open (filename, FileMode.Open); 28 | } 29 | 30 | /// 31 | /// HACK: aapt2 is creating zip entries on Windows such as `assets\subfolder/asset2.txt` 32 | /// 33 | public void FixupWindowsPathSeparators (Action onRename) 34 | { 35 | bool modified = false; 36 | foreach (var entry in archive) { 37 | if (entry.FullName.Contains ("\\")) { 38 | var name = entry.FullName.Replace ('\\', '/'); 39 | onRename?.Invoke (entry.FullName, name); 40 | entry.Rename (name); 41 | modified = true; 42 | } 43 | } 44 | if (modified) { 45 | Flush (); 46 | } 47 | } 48 | 49 | public void Dispose () 50 | { 51 | Dispose(true); 52 | GC.SuppressFinalize (this); 53 | } 54 | 55 | protected virtual void Dispose(bool disposing) { 56 | if (disposing) { 57 | if (archive != null) { 58 | archive.Close (); 59 | archive.Dispose (); 60 | archive = null; 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ExtraField_UnixIDBase.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ExtraField_UnixIDBase.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | namespace Xamarin.Tools.Zip 28 | { 29 | abstract class ExtraField_UnixIDBase : ExtraField 30 | { 31 | public ulong? UID { get; internal set; } 32 | public ulong? GID { get; internal set; } 33 | 34 | public ExtraField_UnixIDBase () 35 | { } 36 | 37 | public ExtraField_UnixIDBase (ExtraField ef) : base (ef) 38 | { } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ZipEntry.Unix.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ZipEntry.Unix.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | partial class ZipEntry 31 | { 32 | internal static ZipEntry Create (ZipArchive owner, Native.zip_stat_t stat) 33 | { 34 | if (Environment.OSVersion.Platform == PlatformID.Unix) { 35 | return new UnixZipEntry (owner, stat); 36 | } 37 | else { 38 | return new WindowsZipEntry (owner, stat); 39 | } 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/PlatformServices.Unix.cs: -------------------------------------------------------------------------------- 1 | // 2 | // PlatformServices.Unix.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | public partial class PlatformServices 31 | { 32 | partial void RegisterUnixServices () 33 | { 34 | if (Environment.OSVersion.Platform == PlatformID.Unix) { 35 | RegisterServices (new UnixPlatformServices ()); 36 | } 37 | else { 38 | RegisterServices (new WindowsPlatformServices ()); 39 | } 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ArchiveGlobalFlags.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ArchiveGlobalFlags.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Global archive flags. Enumeration members correspond to the ZIP_AFL_* macros in the 32 | /// zip.h header. 33 | /// 34 | [Flags] 35 | public enum ArchiveGlobalFlags : uint 36 | { 37 | /// 38 | /// Read only -- cannot be cleared 39 | /// 40 | RDOnly = 2u, 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.LibZipSharp.targets.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | 5 | 6 | <_LibZipNativeLibs Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\native\@LibraryBaseFileName@.*"> 7 | x64\%(FileName)%(Extension) 8 | 9 | <_LibZipNativeLibs Include="$(MSBuildThisFileDirectory)..\runtimes\win-arm64\native\@LibraryBaseFileName@.*"> 10 | arm64\%(FileName)%(Extension) 11 | 12 | <_LibZipNativeLibs Include="$(MSBuildThisFileDirectory)..\runtimes\win-x86\native\@LibraryBaseFileName@.*"> 13 | x86\%(FileName)%(Extension) 14 | 15 | <_LibZipNativeLibs Include="$(MSBuildThisFileDirectory)..\runtimes\osx\native\@LibraryBaseFileName@.dylib"> 16 | %(FileName)%(Extension) 17 | 18 | <_LibZipNativeLibs Include="$(MSBuildThisFileDirectory)..\runtimes\linux-x64\native\@LibraryBaseFileName@.so"> 19 | %(FileName)%(Extension) 20 | 21 | <_LibZipNativeLibs Include="$(MSBuildThisFileDirectory)..\runtimes\linux-x64\native\@LibraryBaseFileName@.so.@LibraryVersionMajor@.@LibraryVersionMinor@.@LibraryVersionPatch@.debug"> 22 | %(FileName)%(Extension) 23 | 24 | 25 | %(Link) 26 | PreserveNewest 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Build LibZipSharp", 8 | "type": "shell", 9 | "command": "dotnet build LibZipSharp/libZipSharp.csproj -t:Build", 10 | "group": { 11 | "kind": "build", 12 | "isDefault": true 13 | }, 14 | "problemMatcher": [ 15 | "$msCompile" 16 | ] 17 | }, 18 | { 19 | "label": "Pack LibZipSharp Nuget", 20 | "type": "shell", 21 | "command": "dotnet pack LibZipSharp/libZipSharp.csproj", 22 | "group": { 23 | "kind": "build", 24 | "isDefault": true 25 | }, 26 | "problemMatcher": [ 27 | "$msCompile" 28 | ] 29 | }, 30 | { 31 | "label": "Clean LibZipSharp", 32 | "type": "shell", 33 | "command": "dotnet build LibZipSharp/libZipSharp.csproj -t:Clean", 34 | "group": { 35 | "kind": "build", 36 | "isDefault": true 37 | }, 38 | "problemMatcher": [ 39 | "$msCompile" 40 | ] 41 | }, 42 | { 43 | "label": "Build LibZipSharp Unit Tests", 44 | "type": "shell", 45 | "command": "dotnet build LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj -t:Build -p:ReferenceNuget=False", 46 | "group": { 47 | "kind": "build", 48 | "isDefault": true 49 | }, 50 | "problemMatcher": [ 51 | "$msCompile" 52 | ] 53 | }, 54 | ] 55 | } -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ErrorType.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ErrorType.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | namespace Xamarin.Tools.Zip 28 | { 29 | /// 30 | /// Type of error code. Enumeration members correspond to the ZIP_ET_* macros 31 | /// in the zip.h header file. 32 | /// 33 | public enum ErrorType 34 | { 35 | /// 36 | /// Error code field is unused 37 | /// 38 | None = 0, 39 | 40 | /// 41 | /// Error code field is the value of errno 42 | /// 43 | Sys = 1, 44 | 45 | /// 46 | /// Error code field is zlib error code 47 | /// 48 | Zlib = 2, 49 | 50 | /// 51 | /// Error code field is libzip error code 52 | /// 53 | Libzip = 3, 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ZipArchive.Unix.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Xamarin.Tools.Zip.Properties; 4 | 5 | namespace Xamarin.Tools.Zip 6 | { 7 | public partial class ZipArchive 8 | { 9 | static ZipArchive CreateArchiveInstance (string defaultExtractionDir, IPlatformOptions options) 10 | { 11 | if (Environment.OSVersion.Platform == PlatformID.Unix) { 12 | return new UnixZipArchive (defaultExtractionDir, EnsureOptions (options) as UnixPlatformOptions); 13 | } 14 | else { 15 | return new WindowsZipArchive (defaultExtractionDir, EnsureOptions (options) as WindowsPlatformOptions); 16 | } 17 | } 18 | 19 | static ZipArchive CreateInstanceFromStream (Stream stream, OpenFlags flags = OpenFlags.RDOnly, IPlatformOptions options = null, bool useTempFile = true) 20 | { 21 | if (Environment.OSVersion.Platform == PlatformID.Unix) { 22 | return new UnixZipArchive (stream, EnsureOptions (options) as UnixPlatformOptions, flags, useTempFile); 23 | } 24 | else { 25 | return new WindowsZipArchive (stream, EnsureOptions (options) as WindowsPlatformOptions, flags, useTempFile); 26 | } 27 | } 28 | 29 | static IPlatformOptions EnsureOptions (IPlatformOptions options) 30 | { 31 | if (Environment.OSVersion.Platform == PlatformID.Unix) { 32 | if (options == null) 33 | return new UnixPlatformOptions (); 34 | else { 35 | var opts = options as UnixPlatformOptions; 36 | if (opts == null) 37 | throw new ArgumentException (string.Format (Resources.MustBeAnInstanceOf_string_type, nameof (options), typeof (UnixPlatformOptions).Name), nameof (options)); 38 | return opts; 39 | } 40 | } 41 | else { 42 | if (options == null) 43 | return new WindowsPlatformOptions (); 44 | else { 45 | var opts = options as WindowsPlatformOptions; 46 | if (opts == null) 47 | throw new ArgumentException (string.Format (Resources.MustBeAnInstanceOf_string_type, nameof (options), typeof (WindowsPlatformOptions).Name), nameof (options)); 48 | return opts; 49 | } 50 | } 51 | 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /ZipTest/ZipTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Exe 6 | ZipTest 7 | ZipTest 8 | net45 9 | false 10 | 11 | 12 | $(DefineConstants);UNIX 13 | 14 | 15 | $(DefineConstants);WINDOWS 16 | 17 | 18 | 19 | 20 | 21 | 22 | $(_NativeLibraryBaseName).dll 23 | Always 24 | 25 | 26 | x64\$(_NativeLibraryBaseName).dll 27 | Always 28 | 29 | 30 | $(_NativeLibraryBaseName).dylib 31 | Always 32 | 33 | 34 | 35 | 36 | 37 | {E248B2CA-303B-4645-ADDC-9D4459D550FD} 38 | libZipSharp 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/WindowsZipEntry.cs: -------------------------------------------------------------------------------- 1 | // 2 | // WindowsZipEntry.cs 3 | // 4 | // Author: 5 | // Dean Ellis 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | namespace Xamarin.Tools.Zip 28 | { 29 | public class WindowsZipEntry : ZipEntry 30 | { 31 | /// 32 | /// Gets the last access time of the ZIP entry. The value is in the UTC timezone. 33 | /// 34 | /// Last access time or if invalid/unset 35 | public DateTime AccessTime { get; internal set; } = DateTime.MinValue; 36 | 37 | /// 38 | /// Gets the creation time of the ZIP entry. The value is in the UTC timezone. 39 | /// 40 | /// Creation time or if invalid/unset 41 | public DateTime CreationTime { get; internal set; } = DateTime.MinValue; 42 | 43 | internal WindowsZipEntry (ZipArchive archive, Native.zip_stat_t stat) 44 | : base (archive, stat) 45 | { } 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /ZipBenchmark/ZipBenchmark.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | disable 7 | enable 8 | 9 | 10 | 11 | $(DefineConstants);UNIX 12 | 13 | 14 | $(DefineConstants);WINDOWS 15 | 16 | 17 | 18 | 19 | $(_NativeLibraryBaseName).dll 20 | Always 21 | 22 | 23 | x64\$(_NativeLibraryBaseName).dll 24 | Always 25 | 26 | 27 | $(_NativeLibraryBaseName).dylib 28 | Always 29 | 30 | 31 | $(_NativeLibraryBaseName).so 32 | Always 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | {E248B2CA-303B-4645-ADDC-9D4459D550FD} 41 | libZipSharp 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /yaml-templates/use-dot-net.yaml: -------------------------------------------------------------------------------- 1 | # This template enables installation of stable and master/nighly builds of .NET. 2 | # We prefer this over the UseDotNet task so that we can always clean up old/unstable versions on disk. 3 | 4 | parameters: 5 | version: $(DotNetCoreVersion) 6 | remove_dotnet: false 7 | 8 | steps: 9 | 10 | - powershell: | 11 | $ErrorActionPreference = 'Stop' 12 | $ProgressPreference = 'SilentlyContinue' 13 | $DotNetRoot = "$env:ProgramFiles\dotnet\" 14 | if ("${{ parameters.remove_dotnet }}" -eq $true) { 15 | Remove-Item -Recurse $DotNetRoot -Verbose 16 | } 17 | Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1 18 | & .\dotnet-install.ps1 -Version ${{ parameters.version }} -InstallDir $DotNetRoot -Verbose 19 | & dotnet --list-sdks 20 | displayName: install .NET Core ${{ parameters.version }} 21 | condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT')) 22 | - bash: > 23 | DOTNET_ROOT=~/.dotnet/ && 24 | (if [[ "${{ parameters.remove_dotnet }}" == "true" ]] ; then rm -rfv $DOTNET_ROOT; fi) && 25 | curl -L https://dot.net/v1/dotnet-install.sh > dotnet-install.sh && 26 | chmod +x dotnet-install.sh && 27 | ./dotnet-install.sh --version ${{ parameters.version }} --install-dir $DOTNET_ROOT --verbose && 28 | PATH="$DOTNET_ROOT:$PATH" && 29 | dotnet --list-sdks && 30 | echo "##vso[task.setvariable variable=DOTNET_ROOT]$DOTNET_ROOT" && 31 | echo "##vso[task.setvariable variable=PATH]$PATH" 32 | displayName: install .NET Core ${{ parameters.version }} 33 | condition: and(succeeded(), eq(variables['agent.os'], 'Darwin')) 34 | - bash: > 35 | DOTNET_ROOT=~/.dotnet/ && 36 | (if [[ "${{ parameters.remove_dotnet }}" == "true" ]] ; then rm -rfv $DOTNET_ROOT; fi) && 37 | curl -L https://dot.net/v1/dotnet-install.sh > dotnet-install.sh && 38 | chmod +x dotnet-install.sh && 39 | ./dotnet-install.sh --version ${{ parameters.version }} --install-dir $DOTNET_ROOT --verbose && 40 | PATH="$DOTNET_ROOT:$PATH" && 41 | dotnet --list-sdks && 42 | echo "##vso[task.setvariable variable=DOTNET_ROOT]$DOTNET_ROOT" && 43 | echo "##vso[task.setvariable variable=PATH]$PATH" 44 | displayName: install .NET Core ${{ parameters.version }} 45 | condition: and(succeeded(), eq(variables['agent.os'], 'Linux')) -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/OpenFlags.cs: -------------------------------------------------------------------------------- 1 | // 2 | // OpenFlags.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Archive open flags. Enumeration members correspond to the ZIP_{ENUM_MEMBER} flags 32 | /// in zip.h 33 | /// 34 | [Flags] 35 | enum OpenFlags 36 | { 37 | /// 38 | /// No flags are set 39 | /// 40 | None = 0, 41 | 42 | /// 43 | /// Create the archive if it does not exist. 44 | /// 45 | Create = 1, 46 | 47 | /// 48 | /// Error if archive already exists. 49 | /// 50 | Excl = 2, 51 | 52 | /// 53 | /// Perform additional stricter consistency checks on the archive, and error if they fail. 54 | /// 55 | CheckCons = 4, 56 | 57 | /// 58 | /// If archive exists, ignore its current contents. In other words, handle it the same way as an empty archive. 59 | /// 60 | Truncate = 8, 61 | 62 | /// 63 | /// Open archive in read-only mode. 64 | /// 65 | RDOnly = 16, 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/EntryPermissions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // EntryPermissions.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | namespace Xamarin.Tools.Zip 28 | { 29 | /// 30 | /// ZIP (as opposed to filesystem) entry permission bits. The bits are used only 31 | /// on the Unix systems. 32 | /// 33 | [Flags] 34 | public enum EntryPermissions : uint 35 | { 36 | Default = 0, 37 | 38 | OwnerRead = UnixExternalPermissions.IRUSR, 39 | OwnerWrite = UnixExternalPermissions.IWUSR, 40 | OwnerExecute = UnixExternalPermissions.IXUSR, 41 | OwnerAll = OwnerRead | OwnerWrite | OwnerExecute, 42 | 43 | GroupRead = UnixExternalPermissions.IRGRP, 44 | GroupWrite = UnixExternalPermissions.IWGRP, 45 | GroupExecute = UnixExternalPermissions.IXGRP, 46 | GroupAll = GroupRead | GroupWrite | GroupExecute, 47 | 48 | WorldRead = UnixExternalPermissions.IROTH, 49 | WorldWrite = UnixExternalPermissions.IWOTH, 50 | WorldExecute = UnixExternalPermissions.IXOTH, 51 | WorldAll = WorldRead | WorldWrite | WorldExecute, 52 | 53 | SetUserId = UnixExternalPermissions.ISUID, 54 | SetGroupId = UnixExternalPermissions.ISGID, 55 | SetDirectoryPermissionControl = UnixExternalPermissions.ISVTX, 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/UnixZipEntry.Unix.cs: -------------------------------------------------------------------------------- 1 | // 2 | // UnixZipEntry.Unix.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | using Mono.Unix.Native; 29 | 30 | namespace Xamarin.Tools.Zip 31 | { 32 | partial class UnixZipEntry 33 | { 34 | internal const FilePermissions DefaultDirMode = FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR | 35 | FilePermissions.S_IRGRP | FilePermissions.S_IXGRP | 36 | FilePermissions.S_IROTH | FilePermissions.S_IXOTH; 37 | internal const FilePermissions DefaultFileMode = FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH; 38 | 39 | FilePermissions? permissions; 40 | 41 | partial void SetFilePermissions (uint value) 42 | { 43 | if (!Enum.IsDefined (typeof (FilePermissions), value)) 44 | throw new ArgumentOutOfRangeException (nameof (value), $"value {value} does not map exactly to FilePermissions"); 45 | 46 | FilePermissions = (FilePermissions)value; 47 | } 48 | 49 | internal FilePermissions FilePermissions { 50 | get { 51 | if (permissions.HasValue) 52 | return permissions.Value; 53 | 54 | return IsDirectory ? DefaultDirMode : DefaultFileMode; 55 | } 56 | 57 | set { permissions = value; } 58 | } 59 | 60 | uint GetPermissions () 61 | { 62 | return (uint)FilePermissions; 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/WindowsZipArchive.cs: -------------------------------------------------------------------------------- 1 | // 2 | // WindowsZipArchive.cs 3 | // 4 | // Author: 5 | // Dean Ellis 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | using System.IO; 28 | using Xamarin.Tools.Zip.Properties; 29 | 30 | namespace Xamarin.Tools.Zip 31 | { 32 | public class WindowsZipArchive : ZipArchive 33 | { 34 | internal WindowsPlatformOptions UnixOptions { 35 | get { 36 | var opts = Options as WindowsPlatformOptions; 37 | if (opts == null) 38 | throw new InvalidOperationException (string.Format (Resources.UnexpectedOptionsType_string_type_type, nameof (Options), typeof (WindowsPlatformOptions).Name, Options?.GetType ()?.Name ?? "Unknown")); 39 | return opts; 40 | } 41 | } 42 | 43 | internal WindowsZipArchive (string defaultExtractionDir, WindowsPlatformOptions options) : base (defaultExtractionDir, options) 44 | { 45 | } 46 | 47 | internal WindowsZipArchive (Stream stream, WindowsPlatformOptions options, OpenFlags flags, bool useTempFile) : base (stream, options, flags, useTempFile) 48 | { 49 | } 50 | 51 | internal bool SetEntryUnixPermissions (ulong index, EntryPermissions requestedPermissions, UnixExternalPermissions unixPermissions) 52 | { 53 | var permissions = (uint)requestedPermissions | (uint)unixPermissions; 54 | int ret = Native.zip_file_set_external_attributes (ArchivePointer, index, OperationFlags.None, (byte)OperatingSystem.UNIX, permissions << 16); 55 | return ret == 0; 56 | } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/StatFlags.cs: -------------------------------------------------------------------------------- 1 | // 2 | // StatFlags.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Flags to indicate which fields of the zip stat structure are valid. Enumeration members 32 | /// correspond to the ZIP_STAT_* macros in the zip.h header file. 33 | /// 34 | [Flags] 35 | public enum StatFlags : ulong 36 | { 37 | /// 38 | /// The Name field is valid 39 | /// 40 | Name = 0x0001u, 41 | 42 | /// 43 | /// The Index field is valid 44 | /// 45 | Index = 0x0002u, 46 | 47 | /// 48 | /// The Size field is valid 49 | /// 50 | Size = 0x0004u, 51 | 52 | /// 53 | /// The CompressedSize field is valid 54 | /// 55 | CompSize = 0x0008u, 56 | 57 | /// 58 | /// The MTime field is valid 59 | /// 60 | MTime = 0x0010u, 61 | 62 | /// 63 | /// The CRC field is valid 64 | /// 65 | CRC = 0x0020u, 66 | 67 | /// 68 | /// The CompressionMethod field is valid 69 | /// 70 | CompMethod = 0x0040u, 71 | 72 | /// 73 | /// The EncryptionMethod field is valid 74 | /// 75 | EncryptionMethod = 0x0080u, 76 | 77 | /// 78 | /// The Flags field is valid 79 | /// 80 | Flags = 0x0100u, 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ExtraField_InfoZipUnixType2.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ExtraField_InfoZipUnixType2.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | class ExtraField_InfoZipUnixType2 : ExtraField_UnixIDBase 31 | { 32 | public ExtraField_InfoZipUnixType2 () 33 | { } 34 | 35 | public ExtraField_InfoZipUnixType2 (ExtraField ef) : base (ef) 36 | { } 37 | 38 | // 39 | // Local-header version: 40 | // Value Size Description 41 | // ----- ---- ----------- 42 | // (Unix2) 0x7855 Short tag for this extra block type ("Ux") 43 | // TSize Short total data size for this block (4) 44 | // UID Short Unix user ID 45 | // GID Short Unix group ID 46 | // 47 | // Central-header version: 48 | // 49 | // Value Size Description 50 | // ----- ---- ----------- 51 | // (Unix2) 0x7855 Short tag for this extra block type ("Ux") 52 | // TSize Short total data size for this block (0) 53 | // 54 | // The data size of the central-header version is zero; it is used 55 | // solely as a flag that UID/GID info is present in the local-header 56 | // extra field. 57 | // 58 | protected override void Parse () 59 | { 60 | base.Parse (); 61 | 62 | DataValid = false; 63 | if (!Local) 64 | return; 65 | 66 | byte [] data = RawData; 67 | if (data?.Length < 4) 68 | return; 69 | 70 | UID = BytesToUnsignedShort (data, 0); 71 | GID = BytesToUnsignedShort (data, 2); 72 | DataValid = true; 73 | } 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/UnixZipEntry.cs: -------------------------------------------------------------------------------- 1 | // 2 | // UnixZipEntry.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | public partial class UnixZipEntry : ZipEntry 31 | { 32 | /// 33 | /// Unix permissions for the entry 34 | /// 35 | /// The permissions. 36 | public uint Permissions { 37 | get { return GetPermissions (); } 38 | set { SetFilePermissions (value); } 39 | } 40 | 41 | /// 42 | /// Unix User ID for the entry, if any 43 | /// 44 | /// Entry user ID. 45 | public ulong? UID { get; set; } 46 | 47 | /// 48 | /// Unix Group ID for the entry, if any 49 | /// 50 | /// Entry group ID 51 | public ulong? GID { get; set; } 52 | 53 | /// 54 | /// Gets the last access time of the ZIP entry. The value is in the UTC timezone. 55 | /// 56 | /// Last access time or if invalid/unset 57 | public DateTime AccessTime { get; internal set; } = DateTime.MinValue; 58 | 59 | /// 60 | /// Gets the creation time of the ZIP entry. The value is in the UTC timezone. 61 | /// 62 | /// Creation time or if invalid/unset 63 | public DateTime CreationTime { get; internal set; } = DateTime.MinValue; 64 | 65 | /// 66 | /// Indicates whether this entry represents a symbolic link 67 | /// 68 | /// true for a symbolic link 69 | public bool IsSymlink { get; internal set; } 70 | 71 | internal UnixZipEntry (ZipArchive archive, Native.zip_stat_t stat) 72 | : base (archive, stat) 73 | {} 74 | 75 | partial void SetFilePermissions (uint value); 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/UnixZipArchive.cs: -------------------------------------------------------------------------------- 1 | // 2 | // UnixZipArchive.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | using System.IO; 28 | using System.Text; 29 | 30 | namespace Xamarin.Tools.Zip 31 | { 32 | public class UnixZipArchive : ZipArchive 33 | { 34 | public UnixPlatformOptions UnixOptions { 35 | get { 36 | var opts = Options as UnixPlatformOptions; 37 | if (opts == null) 38 | throw new InvalidOperationException ("Unexpected options type"); 39 | return opts; 40 | } 41 | } 42 | 43 | internal UnixZipArchive (string defaultExtractionDir, UnixPlatformOptions options) : base (defaultExtractionDir, options) 44 | { 45 | } 46 | 47 | internal UnixZipArchive (Stream stream, UnixPlatformOptions options, OpenFlags flags, bool useTempFile) : base (stream, options, flags, useTempFile) 48 | { 49 | } 50 | 51 | public ZipEntry CreateSymbolicLink (string linkName, string linkDestination, EntryPermissions requestedPermissions = EntryPermissions.Default, Encoding encoding = null) 52 | { 53 | ZipEntry entry = AddEntry (linkName, linkDestination, encoding ?? Encoding.UTF8, CompressionMethod.Store); 54 | if (entry == null) 55 | return null; 56 | if (!SetEntryUnixPermissions (entry.Index, requestedPermissions == EntryPermissions.Default ? DefaultFilePermissions : requestedPermissions, UnixExternalPermissions.IFLNK)) 57 | throw GetErrorException (); 58 | 59 | // We read it again to update permissions, flags, extra fields etc 60 | return ReadEntry (entry.Index); 61 | } 62 | 63 | internal bool SetEntryUnixPermissions (ulong index, EntryPermissions requestedPermissions, UnixExternalPermissions unixPermissions) 64 | { 65 | var permissions = (uint)requestedPermissions | (uint)unixPermissions; 66 | int ret = Native.zip_file_set_external_attributes (ArchivePointer, index, OperationFlags.None, (byte)OperatingSystem.UNIX, permissions << 16); 67 | return ret == 0; 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ZipEntryEnumerator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ZipEntryEnumerator.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | using System.Collections; 28 | using System.Collections.Generic; 29 | 30 | namespace Xamarin.Tools.Zip 31 | { 32 | class ZipEntryEnumerator : IEnumerator 33 | { 34 | ZipArchive archive; 35 | ZipEntry current; 36 | ulong index; 37 | bool start; 38 | 39 | public ZipEntry Current { 40 | get { return ReadEntry (index); } 41 | } 42 | 43 | object IEnumerator.Current { 44 | get { return Current; } 45 | } 46 | 47 | public ZipEntryEnumerator (ZipArchive archive) 48 | { 49 | if (archive == null) 50 | throw new ArgumentNullException (nameof (archive)); 51 | this.archive = archive; 52 | index = 0; 53 | Reset (); 54 | } 55 | 56 | public bool MoveNext () 57 | { 58 | if (!start) 59 | index++; 60 | else 61 | start = false; 62 | 63 | // Calling it each time because the archive can change in the meantime 64 | long nentries = archive.EntryCount; 65 | if (nentries < 0) 66 | return false; 67 | 68 | // Skip past any deleted entires 69 | while (index < (ulong)nentries && ReadEntry (index) == null) { 70 | ++index; 71 | } 72 | 73 | if (index >= (ulong)nentries) 74 | return false; 75 | return true; 76 | } 77 | 78 | public void Reset () 79 | { 80 | start = true; 81 | index = 0; 82 | } 83 | 84 | public void Dispose () 85 | { 86 | archive = null; 87 | current = null; 88 | } 89 | 90 | ZipEntry ReadEntry (ulong index) 91 | { 92 | if (start) 93 | return null; 94 | 95 | if (current != null && current.Index == index) 96 | return current; 97 | 98 | current = archive.ReadEntry (index, throwIfDeleted:false); 99 | return current; 100 | } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /LibZipSharp/libZipSharp.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Xamarin.LibZipSharp.targets 28 | Constants.cs 29 | 30 | 31 | 33 | 34 | $(XamarinLibZipSharpTargetsName).in 35 | $(IntermediateOutputPath)/$(XamarinLibZipSharpTargetsName) 36 | Xamarin.Tools.Zip/$(ConstantsName).in 37 | $(IntermediateOutputPath)/$(ConstantsName) 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/IPlatformServices.cs: -------------------------------------------------------------------------------- 1 | // 2 | // IPlatformServices.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System.Collections.Generic; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Platform-specific services to manage aspects of the ZIP archive specific to a givem platform/operating system 32 | /// 33 | public interface IPlatformServices 34 | { 35 | /// 36 | /// Checks whether the filesystem location identified by is a regular 37 | /// file. Irregular files include device nodes, sockets, character or block devices on Unix systems etc. 38 | /// 39 | /// true if operation was successful, false otherwise 40 | /// ZipArchive to operate on 41 | /// Path to the filesystem location 42 | /// true if points to regular file 43 | bool IsRegularFile (ZipArchive archive, string path, out bool result); 44 | bool IsDirectory (ZipArchive archive, string path, out bool result); 45 | bool GetFilesystemPermissions (ZipArchive archive, string path, out EntryPermissions permissions); 46 | bool StoreSpecialFile (ZipArchive archive, string sourcePath, string archivePath, out long index, out CompressionMethod compressionMethod); 47 | bool SetEntryPermissions (ZipArchive archive, string sourcePath, ulong index, EntryPermissions permissions); 48 | bool SetEntryPermissions (ZipArchive archive, ulong index, EntryPermissions permissions, bool isDirectory); 49 | bool ReadAndProcessExtraFields (ZipEntry entry); 50 | bool WriteExtraFields (ZipArchive archive, ZipEntry entry, IList extraFields); 51 | bool WriteExtraFields (ZipArchive archive, ZipEntry entry, params ExtraField[] extraFields); 52 | bool SetFileProperties (ZipEntry entry, string extractedFilePath, bool throwOnNativeErrors); 53 | bool ExtractSpecialFile (ZipEntry entry, string destinationDir); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LibZipSharp 2 | A managed wrapper (and then some) around libzip (https://libzip.org/) 3 | 4 | [![Build Status](https://devdiv.visualstudio.com/DevDiv/_apis/build/status/xamarin.LibZipSharp?repoName=xamarin%2FLibZipSharp&branchName=main)](https://devdiv.visualstudio.com/DevDiv/_build/latest?definitionId=11678&repoName=xamarin%2FLibZipSharp&branchName=main) 5 | 6 | 7 | The core of `LibZipSharp` is the `ZipArchive` class. You can use this class 8 | to create/extract/update zip file. 9 | 10 | ## Create a new Zip 11 | 12 | To create a new archive use the `FileMode.CreateNew`, this will behave 13 | exactly as it does with normal `File` operations. An exception will be 14 | thrown if the file already exists. 15 | 16 | ``` 17 | using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) { 18 | } 19 | ``` 20 | 21 | ## Open am existing Zip 22 | 23 | To open an existing zip file use `FileMode.Open`. 24 | 25 | ``` 26 | using (var zip = ZipArchive.Open ("test.zip", FileMode.Open)) { 27 | } 28 | ``` 29 | 30 | ## Add files to Zip 31 | 32 | There are a number of methods which can be used to add items to 33 | the zip file. The simplest is `AddFile`. This takes a file path. 34 | If filename is an absolute path, it will be converted to a relative 35 | one by removing the root of the path (i.e. the leading `/` part on 36 | Unix systems and the `x:\\` part on Windows). You can also pass an 37 | `archivePath` parameter where you can specify the name/path which file 38 | will have within the archive. 39 | 40 | ``` 41 | using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) { 42 | zip.AddFile ("somefile.txt"); 43 | } 44 | ``` 45 | 46 | You can also add data directly from a `MemoryStream` via the `AddEntry` 47 | method. This takes an `entryName` and a `MemoryStream`. Note the `MemoryStream` 48 | will be disposed of when the zip file is finally written to disk. 49 | 50 | ``` 51 | var ms = new MemoryStream (); 52 | // write data to stream. 53 | using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) { 54 | zip.AddEntry ("foo", ms); 55 | } 56 | ``` 57 | 58 | You can also add text directly via the `AddEntry` method. This method 59 | takes an `entryName` and `text` parameters. The `entryName` defines 60 | what the item in the zip file will be called. The `text` defines the contents 61 | on the entry. There is also an `encoding` parameter where you can define 62 | the `Encoding` of the file. 63 | 64 | ``` 65 | using (var zip = ZipArchive.Open ("test.zip", FileMode.CreateNew)) { 66 | zip.AddEntry ("foo", "contents of the file", Encoding.UTF8); 67 | } 68 | ``` 69 | 70 | # Shipping the native libraries. 71 | 72 | By default the native libraries will NOT be copied into the output directory 73 | of your app. `.Net Core` apps will pick these files up automatically. However 74 | for Mono you will need the `libzip.*` files in the same directory as the 75 | final app for this library to work. Setting the `LibZipSharpBundleAllNativeLibraries` 76 | MSBuild property to `true` will make sure the native libraries for 77 | ALL supported platforms are copied to the output directory. 78 | 79 | You can do this via the command line 80 | 81 | ``` 82 | /p:LibZipSharpBundleAllNativeLibraries=True 83 | ``` 84 | 85 | or by adding the following to you `csproj`. 86 | 87 | ``` 88 | true 89 | ``` 90 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ExtraField_InfoZipUnix3rdGeneration.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ExtraField_InfoZipUnix3rdGeneration.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | class ExtraField_InfoZipUnix3rdGeneration : ExtraField_UnixIDBase 31 | { 32 | public ExtraField_InfoZipUnix3rdGeneration () 33 | { } 34 | 35 | public ExtraField_InfoZipUnix3rdGeneration (ExtraField ef) : base (ef) 36 | { } 37 | 38 | // 39 | // Value Size Description 40 | // ----- ---- ----------- 41 | // (UnixN) 0x7875 Short tag for this extra block type ("ux") 42 | // TSize Short total data size for this block 43 | // Version 1 byte version of this extra field, currently 1 44 | // UIDSize 1 byte Size of UID field 45 | // UID Variable UID for this entry 46 | // GIDSize 1 byte Size of GID field 47 | // GID Variable GID for this entry 48 | // 49 | protected override void Parse () 50 | { 51 | base.Parse (); 52 | 53 | DataValid = false; 54 | byte [] data = RawData; 55 | if (data?.Length < 5) 56 | return; 57 | 58 | if (data [0] > 1) // version 59 | return; 60 | 61 | ulong id; 62 | byte size = data [1]; 63 | int index = 2; 64 | if (GetID (size, index, data, out id)) { 65 | UID = id; 66 | } 67 | index += size; 68 | 69 | size = data [index++]; 70 | if (GetID (size, index, data, out id)) { 71 | GID = id; 72 | } 73 | 74 | DataValid = true; 75 | } 76 | 77 | bool GetID (byte size, int index, byte[] data, out ulong id) 78 | { 79 | switch (size) { 80 | case 1: 81 | id = data [2]; 82 | return true; 83 | 84 | case 2: 85 | id = BytesToUnsignedShort (data, index); 86 | return true; 87 | 88 | case 4: 89 | id = BytesToUnsignedInt (data, index); 90 | return true; 91 | 92 | case 8: 93 | id = BytesToUnsignedLong (data, index); 94 | return true; 95 | } 96 | 97 | id = 0; 98 | return false; 99 | } 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /ZipBenchmark/Performance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using BenchmarkDotNet.Attributes; 6 | using Xamarin.Tools.Zip; 7 | using SIOC = System.IO.Compression; 8 | 9 | [MemoryDiagnoser] 10 | public class Performance 11 | { 12 | 13 | static byte [] data = []; 14 | static Dictionary files = new Dictionary (); 15 | 16 | static Stream? sicZip = null; 17 | static Stream? libZip = null; 18 | 19 | [GlobalSetup] 20 | public void Setup () 21 | { 22 | Random r = new Random (234234); 23 | for (int j = 0; j < 100; j++) { 24 | data = new byte [r.Next (100, 1024 * 1000)]; 25 | for (int i = 0; i < data.Length; i++) 26 | data [i] = (byte)r.Next (0, 128);// Add a bunch of ascii characters. 27 | files.Add ($"file-{j}.dat", data); 28 | } 29 | sicZip = new MemoryStream (); 30 | using (var zip = new SIOC.ZipArchive (sicZip, SIOC.ZipArchiveMode.Create, leaveOpen: true)) { 31 | foreach (var file in files) { 32 | var entry = zip.CreateEntry (file.Key); 33 | using (var writer = new StreamWriter (entry.Open ())) { 34 | writer.Write (file.Value); 35 | } 36 | } 37 | } 38 | libZip = new MemoryStream (); 39 | using (var zip = ZipArchive.Create (libZip, strictConsistencyChecks: false)) { 40 | foreach (var file in files) { 41 | zip.AddEntry (file.Value, file.Key); 42 | } 43 | zip.Close (); 44 | } 45 | } 46 | 47 | [Benchmark] 48 | public void SystemIOCompressionCreateZip () 49 | { 50 | using var stream = new MemoryStream (); 51 | using (var zip = new SIOC.ZipArchive (stream, SIOC.ZipArchiveMode.Create)) { 52 | foreach (var file in files) { 53 | var entry = zip.CreateEntry (file.Key, SIOC.CompressionLevel.SmallestSize); 54 | using (var writer = new StreamWriter (entry.Open ())) { 55 | writer.Write (file.Value); 56 | } 57 | } 58 | } 59 | } 60 | 61 | [Benchmark] 62 | public void LibZipSharpCreateZip () 63 | { 64 | using var stream = new MemoryStream (); 65 | using (var zip = ZipArchive.Create (stream, strictConsistencyChecks: false, useTempFile: false)) { 66 | foreach (var file in files) { 67 | zip.AddEntry (file.Value, file.Key); 68 | } 69 | zip.Close (); 70 | } 71 | } 72 | 73 | [Benchmark] 74 | public void SystemIOCompressionExtractToMemory () 75 | { 76 | using var ms = new MemoryStream (); 77 | sicZip!.Position = 0; 78 | using (var zi = new SIOC.ZipArchive (sicZip, SIOC.ZipArchiveMode.Read, leaveOpen: true)) { 79 | foreach (var entry in zi.Entries) { 80 | ms.Position= 0; 81 | entry.Open ().CopyTo (ms); 82 | } 83 | } 84 | } 85 | 86 | [Benchmark] 87 | public void LibZipSharpExtractToMemory () 88 | { 89 | using var ms = new MemoryStream (); 90 | libZip!.Position = 0; 91 | using (var zi = ZipArchive.Open (libZip, useTempFile: false)) { 92 | foreach (var entry in zi) { 93 | ms.Position= 0; 94 | entry.Extract (ms); 95 | } 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/OperationFlags.cs: -------------------------------------------------------------------------------- 1 | // 2 | // OperationFlags.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Operation flags, used by NameLocate, Fopen, Stat etc. Enumeration names correspond to the 32 | /// ZIP_FL_* constants in zip.h 33 | /// 34 | [Flags] 35 | public enum OperationFlags : uint 36 | { 37 | /// 38 | /// No flags are set/used 39 | /// 40 | None = 0u, 41 | 42 | /// 43 | /// Ignore case on name lookup 44 | /// 45 | NoCase = 1u, 46 | 47 | /// 48 | /// Ignore directory component 49 | /// 50 | NoDir = 2u, 51 | 52 | /// 53 | /// Read compressed data 54 | /// 55 | Compressed = 4u, 56 | 57 | /// 58 | /// Use original data, ignoring changes 59 | /// 60 | Unchanged = 8u, 61 | 62 | /// 63 | /// Force recompression of data 64 | /// 65 | Recompress = 16u, 66 | 67 | /// 68 | /// Read encrypted data (implies COMPRESSED) 69 | /// 70 | Encrypted = 32u, 71 | 72 | /// 73 | /// Guess string encoding (is default) 74 | /// 75 | Enc_Guess = 0u, 76 | 77 | /// 78 | /// Get unmodified string 79 | /// 80 | Enc_Raw = 64u, 81 | 82 | /// 83 | /// Follow specification strictly 84 | /// 85 | Enc_Strict = 128u, 86 | 87 | /// 88 | /// In local header 89 | /// 90 | Local = 256u, 91 | 92 | /// 93 | /// In central directory 94 | /// 95 | Central = 512u, 96 | 97 | /// 98 | /// String is UTF-8 encoded 99 | /// 100 | Enc_UTF_8 = 2048u, 101 | 102 | /// 103 | /// String is CP437 encoded 104 | /// 105 | Enc_CP437 = 4096u, 106 | 107 | /// 108 | /// Zip_file_add: if file with name exists, overwrite (replace) it 109 | /// 110 | Overwrite = 8192u, 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/UnixExternalPermissions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // UnixExternalPermissions.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | // The definitions are taken from InfoZip's unzip sources, from the zipinfo.c 31 | // file. unzip is distributed under the InfoZip license based on BSD 32 | // 33 | // http://www.info-zip.org/pub/infozip/license.html 34 | // 35 | [Flags] 36 | enum UnixExternalPermissions : uint 37 | { 38 | /* Define OS-specific attributes for use on ALL platforms--the S_xxxx 39 | * versions of these are defined differently (or not defined) by different 40 | * compilers and operating systems. 41 | */ 42 | IFMT = 0xF000, /* 0170000 Unix file type mask */ 43 | 44 | IFREG = 0x8000, /* 0100000 Unix regular file */ 45 | IFSOCK = 0xC000, /* 0140000 Unix socket (BSD, not SysV or Amiga) */ 46 | IFLNK = 0xA000, /* 0120000 Unix symbolic link (not SysV, Amiga) */ 47 | IFBLK = 0x6000, /* 0060000 Unix block special (not Amiga) */ 48 | IFDIR = 0x4000, /* 0040000 Unix directory */ 49 | IFCHR = 0x2000, /* 0020000 Unix character special (not Amiga) */ 50 | IFIFO = 0x1000, /* 0010000 Unix fifo (BCC, not MSC or Amiga) */ 51 | 52 | ISUID = 0x0800, /* 04000 Unix set user id on execution */ 53 | ISGID = 0x0400, /* 02000 Unix set group id on execution */ 54 | ISVTX = 0x0200, /* 01000 Unix directory permissions control */ 55 | IRWXU = 0x01C0, /* 00700 Unix read, write, execute: owner */ 56 | IRUSR = 0x0100, /* 00400 Unix read permission: owner */ 57 | IWUSR = 0x0080, /* 00200 Unix write permission: owner */ 58 | IXUSR = 0x0040, /* 00100 Unix execute permission: owner */ 59 | IRWXG = 0x0038, /* 00070 Unix read, write, execute: group */ 60 | IRGRP = 0x0020, /* 00040 Unix read permission: group */ 61 | IWGRP = 0x0010, /* 00020 Unix write permission: group */ 62 | IXGRP = 0x0008, /* 00010 Unix execute permission: group */ 63 | IRWXO = 0x0007, /* 00007 Unix read, write, execute: other */ 64 | IROTH = 0x0004, /* 00004 Unix read permission: other */ 65 | IWOTH = 0x0002, /* 00002 Unix write permission: other */ 66 | IXOTH = 0x0001, /* 00001 Unix execute permission: other */ 67 | 68 | IMODE = ISUID | ISGID | ISVTX | IRWXU | IRUSR | IWUSR | IXUSR | IRWXG | IRGRP | IWGRP | IXGRP | IRWXO | IROTH | IWOTH | IXOTH, 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/OperatingSystem.cs: -------------------------------------------------------------------------------- 1 | // 2 | // OperatingSystem.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Operating system on which the archive was created. Enu,meration members correspond to 32 | /// the ZIP_OPSYS_* macros in the zip.h header file. 33 | /// 34 | public enum OperatingSystem : uint 35 | { 36 | /// 37 | /// DOS 38 | /// 39 | DOS = 0x00u, 40 | 41 | /// 42 | /// Amiga OS 43 | /// 44 | AMIGA = 0x01u, 45 | 46 | /// 47 | /// Open VMS 48 | /// 49 | OPENVMS = 0x02u, 50 | 51 | /// 52 | /// Generic UNIX 53 | /// 54 | UNIX = 0x03u, 55 | 56 | /// 57 | /// VM CMS 58 | /// 59 | VM_CMS = 0x04u, 60 | 61 | /// 62 | /// Atari ST 63 | /// 64 | ATARI_ST = 0x05u, 65 | 66 | /// 67 | /// IBM OS/2 68 | /// 69 | OS_2 = 0x06u, 70 | 71 | /// 72 | /// Classic MacOS 73 | /// 74 | MACINTOSH = 0x07u, 75 | 76 | /// 77 | /// IBM SystemZ 78 | /// 79 | Z_SYSTEM = 0x08u, 80 | 81 | /// 82 | /// CP/M 83 | /// 84 | CPM = 0x09u, 85 | 86 | /// 87 | /// Windows using the NTFS filesystem 88 | /// 89 | WINDOWS_NTFS = 0x0au, 90 | 91 | /// 92 | /// MVS 93 | /// 94 | MVS = 0x0bu, 95 | 96 | /// 97 | /// VSE 98 | /// 99 | VSE = 0x0cu, 100 | 101 | /// 102 | /// Acorn RISC 103 | /// 104 | ACORN_RISC = 0x0du, 105 | 106 | /// 107 | /// VFAT filesystem 108 | /// 109 | VFAT = 0x0eu, 110 | 111 | /// 112 | /// Alternate MVS 113 | /// 114 | ALTERNATE_MVS = 0x0fu, 115 | 116 | /// 117 | /// BeOS 118 | /// 119 | BEOS = 0x10u, 120 | 121 | /// 122 | /// Tandem 123 | /// 124 | TANDEM = 0x11u, 125 | 126 | /// 127 | /// IBM OS/400 128 | /// 129 | OS_400 = 0x12u, 130 | 131 | /// 132 | /// Apple OS X 133 | /// 134 | OS_X = 0x13u, 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ExtraField_InfoZipUnixOriginal.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ExtraField_InfoZipUnixOriginal.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | class ExtraField_InfoZipUnixOriginal : ExtraField 31 | { 32 | public DateTime AccessTime { get; internal set; } = DateTime.MinValue; 33 | public DateTime ModificationTime { get; internal set; } = DateTime.MinValue; 34 | public ushort? UID { get; internal set; } 35 | public ushort? GID { get; internal set; } 36 | 37 | public ExtraField_InfoZipUnixOriginal () 38 | { } 39 | 40 | public ExtraField_InfoZipUnixOriginal (ExtraField ef) : base (ef) 41 | { } 42 | 43 | // Local-header version: 44 | // 45 | // Value Size Description 46 | // ----- ---- ----------- 47 | // (Unix1) 0x5855 Short tag for this extra block type ("UX") 48 | // TSize Short total data size for this block 49 | // AcTime Long time of last access (UTC/GMT) 50 | // ModTime Long time of last modification (UTC/GMT) 51 | // UID Short Unix user ID (optional) 52 | // GID Short Unix group ID (optional) 53 | // 54 | // Central-header version: 55 | // 56 | // Value Size Description 57 | // ----- ---- ----------- 58 | // (Unix1) 0x5855 Short tag for this extra block type ("UX") 59 | // TSize Short total data size for this block 60 | // AcTime Long time of last access (GMT/UTC) 61 | // ModTime Long time of last modification (GMT/UTC) 62 | // 63 | // Note that what we get here is JUST THE DATA - without the ID and TSize fields! 64 | protected override void Parse () 65 | { 66 | base.Parse (); 67 | 68 | ModificationTime = DateTime.MinValue; 69 | AccessTime = DateTime.MinValue; 70 | DataValid = false; 71 | 72 | byte [] data = RawData; 73 | if (data?.Length < 8) 74 | return; 75 | 76 | int index = 0; 77 | ModificationTime = Utilities.DateTimeFromUnixTime (BytesToUnsignedInt (data, index)); 78 | index += 4; 79 | 80 | AccessTime = Utilities.DateTimeFromUnixTime (BytesToUnsignedInt (data, index)); 81 | index += 4; 82 | 83 | if (!Local || data.Length <= 8) 84 | return; 85 | 86 | UID = BytesToUnsignedShort (data, index); 87 | index += 2; 88 | GID = BytesToUnsignedShort (data, index); 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /libZipSharp.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libZipSharp", "LibZipSharp\libZipSharp.csproj", "{E248B2CA-303B-4645-ADDC-9D4459D550FD}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZipTest", "ZipTest\ZipTest.csproj", "{51489C44-3B62-4BEC-B0D1-6BB5DD53E7C9}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTest", "UnitTest", "{6F41E830-1A60-4DE8-B061-10D9164D9F5B}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibZipSharp.UnitTest", "LibZipSharp.UnitTest\LibZipSharp.UnitTest.csproj", "{E66B5FB9-2470-4563-BF28-0C57108369D1}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZipBenchmark", "ZipBenchmark\ZipBenchmark.csproj", "{A94C6974-76CE-4BA9-83A2-69FCBCA77118}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {E248B2CA-303B-4645-ADDC-9D4459D550FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {E248B2CA-303B-4645-ADDC-9D4459D550FD}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {E248B2CA-303B-4645-ADDC-9D4459D550FD}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {E248B2CA-303B-4645-ADDC-9D4459D550FD}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {51489C44-3B62-4BEC-B0D1-6BB5DD53E7C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {51489C44-3B62-4BEC-B0D1-6BB5DD53E7C9}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {51489C44-3B62-4BEC-B0D1-6BB5DD53E7C9}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {51489C44-3B62-4BEC-B0D1-6BB5DD53E7C9}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {E66B5FB9-2470-4563-BF28-0C57108369D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {E66B5FB9-2470-4563-BF28-0C57108369D1}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {E66B5FB9-2470-4563-BF28-0C57108369D1}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {E66B5FB9-2470-4563-BF28-0C57108369D1}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {A94C6974-76CE-4BA9-83A2-69FCBCA77118}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {A94C6974-76CE-4BA9-83A2-69FCBCA77118}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {A94C6974-76CE-4BA9-83A2-69FCBCA77118}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {A94C6974-76CE-4BA9-83A2-69FCBCA77118}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(MonoDevelopProperties) = preSolution 38 | Policies = $0 39 | $0.StandardHeader = $1 40 | $1.Text = @\n${FileName}\n \nAuthor:\n ${AuthorName} <${AuthorEmail}>\n\nCopyright (c) ${Year} ${CopyrightHolder}\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. 41 | EndGlobalSection 42 | GlobalSection(NestedProjects) = preSolution 43 | {E66B5FB9-2470-4563-BF28-0C57108369D1} = {6F41E830-1A60-4DE8-B061-10D9164D9F5B} 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net471;$(_DotNetTargetFramework);netcoreapp3.1 7 | 8 | false 9 | true 10 | False 11 | $(DefineConstants);WINDOWS 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | $(_NativeLibraryBaseName).dylib 27 | PreserveNewest 28 | 29 | 30 | $(_NativeLibraryBaseName).dll 31 | PreserveNewest 32 | 33 | 34 | $(_NativeLibraryBaseName).so 35 | PreserveNewest 36 | 37 | 38 | $(_NativeLibraryBaseName).so.$(_LibZipSharpAssemblyVersionMajor).$(_LibZipSharpAssemblyVersionMinor).$(_LibZipSharpAssemblyVersionPatch).debug 39 | PreserveNewest 40 | 41 | 42 | PreserveNewest 43 | 44 | 45 | PreserveNewest 46 | 47 | 48 | PreserveNewest 49 | 50 | 51 | PreserveNewest 52 | 53 | 54 | 55 | 56 | 57 | mono 58 | 59 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/SourceCommand.cs: -------------------------------------------------------------------------------- 1 | // 2 | // SourceCommand.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Commands sent to user-defined ZIP source callback function/method. Enumeration 32 | /// members correspond to the members of the zip_source_cmd enum defined in 33 | /// the zip.h header file (the ZIP_SOURCE_* symbols). 34 | /// 35 | /// Order of members MUST be the same as in the C enum 36 | /// 37 | public enum SourceCommand 38 | { 39 | /// 40 | /// Prepare for reading. 41 | /// 42 | Open, 43 | 44 | /// 45 | /// Read data into the buffer data of size len. Return the number of bytes placed into data on success. 46 | /// 47 | Read, 48 | 49 | /// 50 | /// Reading is done 51 | /// 52 | Close, 53 | 54 | /// 55 | /// Get meta information 56 | /// 57 | Stat, 58 | 59 | /// 60 | /// Get error information 61 | /// 62 | Error, 63 | 64 | /// 65 | /// Cleanup and free resources 66 | /// 67 | Free, 68 | 69 | /// 70 | /// Set position for reading 71 | /// 72 | Seek, 73 | 74 | /// 75 | /// Get read position 76 | /// 77 | Tell, 78 | 79 | /// 80 | /// Prepare for writing 81 | /// 82 | BeginWrite, 83 | 84 | /// 85 | /// Writing is done 86 | /// 87 | CommitWrite, 88 | 89 | /// 90 | /// Discard written changes 91 | /// 92 | RollbackWrite, 93 | 94 | /// 95 | /// Write data 96 | /// 97 | Write, 98 | 99 | /// 100 | /// Set position for writing 101 | /// 102 | SeekWrite, 103 | 104 | /// 105 | /// Get write position 106 | /// 107 | TellWrite, 108 | 109 | /// 110 | /// Check whether source supports command 111 | /// 112 | Supports, 113 | 114 | /// 115 | /// Remove the underlying file. This is called if a zip archive is empty when closed. 116 | /// 117 | Remove, 118 | 119 | /// 120 | /// Previously used internally 121 | /// 122 | Reserved1, 123 | 124 | /// 125 | /// Like , but keep part of original file 126 | /// 127 | BeginWriteCloning, 128 | 129 | /// 130 | /// Whether empty files are valid archives 131 | /// 132 | AcceptEmpty, 133 | 134 | /// 135 | /// Get additional file attributes 136 | /// 137 | GetFileAttributes, 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/CompressionMethod.cs: -------------------------------------------------------------------------------- 1 | // 2 | // CompressionMethod.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | /// 31 | /// Archive compression method. Enumeration members correspond to the ZIP_CM_* macros in 32 | /// the zip.h header file. 33 | /// 34 | public enum CompressionMethod : short 35 | { 36 | /// 37 | /// Unknown compression method (not present in the native libzip) 38 | /// 39 | Unknown = -2, 40 | 41 | /// 42 | /// Better of deflate or store 43 | /// 44 | Default = -1, 45 | 46 | /// 47 | /// Stored (uncompressed) 48 | /// 49 | Store = 0, 50 | 51 | /// 52 | /// Shrunk 53 | /// 54 | Shrink = 1, 55 | 56 | /// 57 | /// Reduced with factor 1 58 | /// 59 | Reduce_1 = 2, 60 | 61 | /// 62 | /// Reduced with factor 2 63 | /// 64 | Reduce_2 = 3, 65 | 66 | /// 67 | /// Reduced with factor 3 68 | /// 69 | Reduce_3 = 4, 70 | 71 | /// 72 | /// Reduced with factor 4 73 | /// 74 | Reduce_4 = 5, 75 | 76 | /// 77 | /// Imploded 78 | /// 79 | Implode = 6, 80 | 81 | /* 7 - Reserved for Tokenizing compression algorithm */ 82 | 83 | /// 84 | /// Deflated 85 | /// 86 | Deflate = 8, 87 | 88 | /// 89 | /// Deflate (64-bit) 90 | /// 91 | Deflate64 = 9, 92 | 93 | /// 94 | /// PKWARE imploding 95 | /// 96 | PKWare_Implode = 10, 97 | 98 | /* 11 - Reserved by PKWARE */ 99 | 100 | /// 101 | /// Compressed using BZIP2 algorithm 102 | /// 103 | Bzip2 = 12, 104 | 105 | /* 13 - Reserved by PKWARE */ 106 | 107 | /// 108 | /// LZMA (EFS) 109 | /// 110 | LZMA = 14, 111 | 112 | /* 15-17 - Reserved by PKWARE */ 113 | 114 | /// 115 | /// Compressed using IBM TERSE (new) 116 | /// 117 | Terse = 18, 118 | 119 | /// 120 | /// IBM LZ77 z Architecture (PFS) 121 | /// 122 | LZ77 = 19, 123 | 124 | /// 125 | /// LZMA2 Compressed data 126 | /// 127 | LZMA2 = 33, 128 | 129 | /// 130 | /// Zstandard compressed data 131 | /// 132 | ZSTD = 93, 133 | 134 | /// 135 | /// XZ compressed data 136 | /// 137 | XZ = 95, 138 | 139 | /// 140 | /// Compressed Jpeg data 141 | /// 142 | JPEG = 96, 143 | 144 | /// 145 | /// WavPack compressed data 146 | /// 147 | WavPack = 97, 148 | 149 | /// 150 | /// PPMd version I, Rev 1 151 | /// 152 | PPMD = 98, 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /yaml-templates/stage-test.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | - name: use1ESTemplate 3 | type: boolean 4 | default: true 5 | - name: publishTaskPrefix 6 | type: string 7 | default: 1ES. 8 | 9 | stages: 10 | - stage: Test 11 | dependsOn: Build 12 | variables: 13 | DotNetCoreVersion: 3.1.201 14 | DotNetVersion: 7.0.406 15 | jobs: 16 | - job: testlinux 17 | displayName: 'Test Linux' 18 | ${{ if eq(parameters.use1ESTemplate, true) }}: 19 | pool: 20 | name: AzurePipelines-EO 21 | image: $(LinuxPoolImage1ESPT) 22 | os: linux 23 | ${{ else }}: 24 | pool: 25 | name: Azure Pipelines 26 | vmImage: $(LinuxPoolImageHosted) 27 | steps: 28 | - template: /yaml-templates/use-dot-net.yaml 29 | parameters: 30 | version: $(DotNetCoreVersion) 31 | - template: /yaml-templates/use-dot-net.yaml 32 | parameters: 33 | version: $(DotNetVersion) 34 | - task: DownloadPipelineArtifact@2 35 | displayName: download artifacts 36 | inputs: 37 | artifactName: nuget 38 | downloadPath: $(Build.SourcesDirectory) 39 | - task: DotNetCoreCLI@2 40 | displayName: 'Build solution LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj' 41 | inputs: 42 | projects: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj 43 | configuration: Release 44 | arguments: -p:ReferenceNuget=True -v:diag 45 | - task: DotNetCoreCLI@2 46 | displayName: 'Run Unit tests for .net' 47 | inputs: 48 | command: test 49 | projects: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj 50 | configuration: Release 51 | arguments: -p:ReferenceNuget=True -v:diag 52 | 53 | - job: testmacos 54 | displayName: 'Test MacOS' 55 | pool: 56 | name: Azure Pipelines 57 | vmImage: macOS-14 58 | os: macOS 59 | steps: 60 | - template: /yaml-templates/use-dot-net.yaml 61 | parameters: 62 | version: $(DotNetCoreVersion) 63 | - template: /yaml-templates/use-dot-net.yaml 64 | parameters: 65 | version: $(DotNetVersion) 66 | - task: DownloadPipelineArtifact@2 67 | displayName: download artifacts 68 | inputs: 69 | artifactName: nuget 70 | downloadPath: $(Build.SourcesDirectory) 71 | - task: DotNetCoreCLI@2 72 | displayName: 'Build solution LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj' 73 | inputs: 74 | projects: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj 75 | configuration: Release 76 | arguments: -p:ReferenceNuget=True -v:diag 77 | - task: DotNetCoreCLI@2 78 | displayName: 'Run Tests under .net' 79 | inputs: 80 | command: test 81 | projects: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj 82 | configuration: Release 83 | arguments: -p:ReferenceNuget=True -v:diag 84 | 85 | - job: testwindows 86 | displayName: 'Test Windows' 87 | ${{ if eq(parameters.use1ESTemplate, true) }}: 88 | pool: 89 | name: AzurePipelines-EO 90 | image: $(WindowsPoolImage1ESPT) 91 | os: windows 92 | ${{ else }}: 93 | pool: 94 | name: Azure Pipelines 95 | vmImage: $(WindowsPoolImageHosted) 96 | steps: 97 | - template: /yaml-templates/use-dot-net.yaml 98 | parameters: 99 | version: $(DotNetCoreVersion) 100 | - template: /yaml-templates/use-dot-net.yaml 101 | parameters: 102 | version: $(DotNetVersion) 103 | - task: DownloadPipelineArtifact@2 104 | displayName: download artifacts 105 | inputs: 106 | artifactName: nuget 107 | downloadPath: $(Build.SourcesDirectory) 108 | - task: DotNetCoreCLI@2 109 | displayName: 'Build solution LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj' 110 | inputs: 111 | projects: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj 112 | configuration: Release 113 | arguments: -p:ReferenceNuget=True -v:diag 114 | - task: DotNetCoreCLI@2 115 | displayName: 'Run Tests LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj' 116 | inputs: 117 | command: test 118 | projects: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj 119 | configuration: Release 120 | arguments: -p:ReferenceNuget=True -v:diag 121 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ZipIOException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ZipIOException.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | using System.IO; 28 | using System.Runtime.Serialization; 29 | 30 | namespace Xamarin.Tools.Zip 31 | { 32 | /// 33 | /// Zip I/O exception. 34 | /// 35 | public class ZipIOException : IOException 36 | { 37 | /// 38 | /// Native libzip error code, if any. 39 | /// 40 | /// The zip error code. 41 | public ErrorCode ZipErrorCode { get; private set; } = ErrorCode.OK; 42 | 43 | /// 44 | /// Value of the native system errno, on Unix, 0 on Windows. Note that the value is only advisory, 45 | /// it might not have any meaning, depending on context. 46 | /// 47 | /// errno variable value. 48 | public int Errno { get; private set; } = 0; 49 | 50 | /// 51 | /// Initializes a new instance of the class. 52 | /// 53 | public ZipIOException () 54 | {} 55 | 56 | /// 57 | /// Initializes a new instance of the class. 58 | /// 59 | /// Message. 60 | public ZipIOException (string message) : base (message) 61 | {} 62 | 63 | /// 64 | /// Initializes a new instance of the class. 65 | /// 66 | /// Message. 67 | /// Inner exception. 68 | public ZipIOException (string message, Exception inner) : base (message, inner) 69 | {} 70 | 71 | /// 72 | /// Initializes a new instance of the class. 73 | /// 74 | /// Serialization info. 75 | /// Streaming context. 76 | public ZipIOException (SerializationInfo info, StreamingContext context) : base (info, context) 77 | {} 78 | 79 | /// 80 | /// Initializes a new instance of the class. 81 | /// 82 | /// Message. 83 | /// Error code. 84 | /// Errno value. 85 | public ZipIOException (string message, ErrorCode errorCode, int errno = 0) : this (message) 86 | { 87 | CommonInit (errorCode, errno); 88 | } 89 | 90 | /// 91 | /// Initializes a new instance of the class. 92 | /// 93 | /// Message. 94 | /// Inner exception. 95 | /// Error code. 96 | /// Errno value. 97 | public ZipIOException (string message, Exception inner, ErrorCode errorCode, int errno = 0) : this (message, inner) 98 | { 99 | CommonInit (errorCode, errno); 100 | } 101 | 102 | void CommonInit (ErrorCode errorCode, int errno) 103 | { 104 | ZipErrorCode = errorCode; 105 | Errno = errno; 106 | } 107 | } 108 | } 109 | 110 | -------------------------------------------------------------------------------- /LibZipSharp/Xamarin.Tools.Zip/ExtraField.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ExtraField.cs 3 | // 4 | // Author: 5 | // Marek Habersack 6 | // 7 | // Copyright (c) 2016 Xamarin, Inc (http://xamarin.com) 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | using System; 27 | 28 | namespace Xamarin.Tools.Zip 29 | { 30 | public class ExtraField 31 | { 32 | byte [] rawData; 33 | public ushort ID { get; set; } 34 | public ushort Length { get; set; } 35 | public bool Local { get; set; } 36 | public ushort FieldIndex { get; set; } 37 | public ulong EntryIndex { get; set; } 38 | public bool DataValid { get; protected set; } = true; 39 | 40 | public byte [] RawData { 41 | get { 42 | return rawData; 43 | } 44 | set { 45 | rawData = value; 46 | Parse (); 47 | } 48 | } 49 | 50 | public ExtraField () 51 | { } 52 | 53 | public ExtraField (ExtraField ef) 54 | { 55 | if (ef == null) 56 | return; 57 | 58 | ID = ef.ID; 59 | Length = ef.Length; 60 | Local = ef.Local; 61 | FieldIndex = ef.FieldIndex; 62 | EntryIndex = ef.EntryIndex; 63 | DataValid = ef.DataValid; 64 | RawData = ef.RawData; 65 | } 66 | 67 | protected virtual void Parse () 68 | { 69 | DataValid = true; 70 | } 71 | 72 | internal virtual void Encode () 73 | { 74 | DataValid = true; 75 | } 76 | 77 | protected ulong BytesToUnsignedLong (byte [] data, int startIndex) 78 | { 79 | if (data == null) 80 | throw new ArgumentNullException (nameof (data)); 81 | 82 | if (startIndex < 0 || startIndex > data.Length || startIndex + 7 >= data.Length) 83 | throw new ArgumentOutOfRangeException (nameof (startIndex)); 84 | 85 | return (ulong)((data [startIndex + 7] << 56) | 86 | (data [startIndex + 6] << 48) | 87 | (data [startIndex + 5] << 40) | 88 | (data [startIndex + 4] << 32) | 89 | (data [startIndex + 3] << 24) | 90 | (data [startIndex + 2] << 16) | 91 | (data [startIndex + 1] << 8) | 92 | data [startIndex]); 93 | } 94 | 95 | protected byte[] UnsignedIntToBytes (uint data) 96 | { 97 | byte[] result = new byte[4]; 98 | result [0] = (byte)(data); 99 | result [1] = (byte)(data >> 8); 100 | result [2] = (byte)(data >> 16); 101 | result [3] = (byte)(data >> 24); 102 | return result; 103 | } 104 | 105 | protected uint BytesToUnsignedInt (byte [] data, int startIndex) 106 | { 107 | if (data == null) 108 | throw new ArgumentNullException (nameof (data)); 109 | 110 | if (startIndex < 0 || startIndex > data.Length || startIndex + 3 >= data.Length) 111 | throw new ArgumentOutOfRangeException (nameof (startIndex)); 112 | 113 | return (uint)((data [startIndex + 3] << 24) | 114 | (data [startIndex + 2] << 16) | 115 | (data [startIndex + 1] << 8) | 116 | data [startIndex]); 117 | } 118 | 119 | protected ushort BytesToUnsignedShort (byte [] data, int startIndex) 120 | { 121 | if (data == null) 122 | throw new ArgumentNullException (nameof (data)); 123 | 124 | if (startIndex < 0 || startIndex > data.Length || startIndex + 1 >= data.Length) 125 | throw new ArgumentOutOfRangeException (nameof (startIndex)); 126 | 127 | return (ushort)((data [startIndex + 1] << 8) | 128 | data [startIndex]); 129 | } 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /docs/timezone.txt: -------------------------------------------------------------------------------- 1 | Timezone strings: 2 | ----------------- 3 | This is a description of valid timezone strings for ENV[ARC]:TZ: 4 | "XPG3TZ - time zone information" 5 | The form of the time zone information is based on the XPG3 specification of 6 | the TZ environment variable. Spaces are allowed only in timezone 7 | designations, where they are significant. The following description 8 | closely follows the XPG3 specification, except for the paragraphs starting 9 | **CLARIFICATION**. 10 | 11 | [[],[/