Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ jobs:
toolchain: stable
target: x86_64-unknown-linux-musl
use-dlltool-shim: false
- rid: linux-arm64
os: ubuntu-latest
toolchain: stable
target: aarch64-unknown-linux-gnu
use-dlltool-shim: false
cross: gcc-aarch64-linux-gnu
- rid: win-arm64
os: windows-latest
toolchain: stable-x86_64-pc-windows-gnu
target: aarch64-pc-windows-gnullvm
use-dlltool-shim: true
- rid: win-x86
os: windows-latest
toolchain: stable-x86_64-pc-windows-gnu
target: i686-pc-windows-gnu
use-dlltool-shim: true
- rid: osx-x64
os: macos-latest
toolchain: stable
Expand All @@ -63,6 +79,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install cross toolchain
if: matrix.cross
run: sudo apt-get update && sudo apt-get install -y ${{ matrix.cross }}

- name: Configure ARM64 linker
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
Expand Down Expand Up @@ -128,7 +152,7 @@ jobs:
- name: Deploy cores into runtimes/<RID>/native
shell: pwsh
run: |
$rids = @('win-x64','linux-x64','linux-musl-x64','osx-x64','osx-arm64')
$rids = @('win-x64','linux-x64','linux-musl-x64','linux-arm64','win-arm64','win-x86','osx-x64','osx-arm64')
foreach ($rid in $rids) {
$dest = "src/GeneralZip/runtimes/$rid/native"
New-Item -ItemType Directory -Force -Path $dest | Out-Null
Expand All @@ -146,6 +170,7 @@ jobs:
run: |
dotnet build GeneralZip.slnx -c Release -p:Version=${{ env.PACKAGE_VERSION }} --nologo
dotnet pack src/GeneralZip/GeneralZip.csproj -c Release -p:Version=${{ env.PACKAGE_VERSION }} -o artifacts/nuget --nologo
dotnet pack src/GeneralZip.Cli/GeneralZip.Cli.csproj -c Release -p:Version=${{ env.PACKAGE_VERSION }} -o artifacts/nuget --nologo

- name: Smoke test (fresh console app installs packed packages)
shell: pwsh
Expand All @@ -160,7 +185,7 @@ jobs:
using GeneralZip;
using static GeneralZip.GeneralZip;

Initialize();
// 无任何显式引导调用:验证零初始化的隐式引导端到端可用
Console.WriteLine($"native={GeneralZip.Native.NativeCoreLoader.IsAvailable}");

var dir = Path.Combine(Path.GetTempPath(), "gzp-smoke");
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<Deterministic>true</Deterministic>
<Authors>GeneralZip</Authors>
<Version>1.2.0</Version>
<Version>2.0.0</Version>
<Company>GeneralZip</Company>
<Product>GeneralZip</Product>
<!-- Deterministic CI build; inject the commit hash via MinVer-style CI_VERSION if present -->
Expand Down
4 changes: 4 additions & 0 deletions GeneralZip.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
</Folder>
<Folder Name="/src/">
<Project Path="src/GeneralZip/GeneralZip.csproj" />
<Project Path="src/GeneralZip.Cli/GeneralZip.Cli.csproj" />
</Folder>
<Folder Name="/fuzz/">
<Project Path="fuzz/GeneralZip.Fuzz/GeneralZip.Fuzz.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/GeneralZip.Native.Tests/GeneralZip.Native.Tests.csproj" />
Expand Down
98 changes: 74 additions & 24 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

## Why GeneralZip?

- **One API, many formats** — ZIP, 7z, RAR, TAR, GZ, BZ2, XZ, Zstd, LZ4 with automatic magic-byte detection. No more "which library do I need for this file?"
- **Encryption done right** — WinZip AES for universal interop, plus **SM4-GM** (Chinese national cryptography) as a documented custom ZIP extension, all behind one `EncryptionAlgorithm` switch.
- **Built for apps, not just scripts** — full event system (progress, interactive password prompts, overwrite decisions, error policies), `CancellationToken` everywhere, `IProgress<T>` support.
- **Zero third-party NuGet dependencies in the core** — cryptographic primitives (SM3/SM4) and the TAR container are pure C# implementations validated against GB/T standard test vectors; native codecs (7z/bzip2/xz/zstd/lz4) live in an optional Rust native core, all pure Rust.
- **One API, many formats** — ZIP, 7z, RAR, TAR, GZ, BZ2, XZ, Zstd, LZ4, Brotli, CPIO, ISO9660 (read) and CAB (read) with automatic magic-byte detection. No more "which library do I need for this file?"
- **Encryption done right** — WinZip AES for universal interop, **SM4-GM** (Chinese national cryptography) as a documented custom ZIP extension, and an **SM2-GM envelope** (per-entry data keys sealed with SM2 public-key encryption — public-key recipients, no shared passwords). All behind one `EncryptionAlgorithm` switch, with a pluggable KDF registry.
- **Built for apps, not just scripts** — full event system (progress, interactive password prompts, overwrite decisions, error policies), `CancellationToken` everywhere, `IProgress<T>` support, parallel compress/extract, `IAsyncEnumerable` entry enumeration.
- **Zero third-party NuGet dependencies in the core** — SM3/SM4, SM2 encryption and key handling, and the TAR/CPIO containers are C# implementations validated against GB/T standard test vectors. SM2 private-key decryption uses the RustCrypto constant-time implementation in the native core, which is required to read SM2-GM archives; the native codecs (7z/bzip2/xz/zstd/lz4/brotli) are otherwise optional.

## Installation

Expand All @@ -33,9 +33,10 @@ dotnet add package GeneralZip
Targets `netstandard2.0` and `net8.0`.

> One package, everything included. The library bundles prebuilt Rust native cores for
> win-x64, linux-x64, linux-musl-x64, osx-x64 and osx-arm64; `GeneralZip.Initialize()`
> loads them automatically. If the core is missing for your platform, 7z/RAR and the
> native codecs degrade gracefully; everything else keeps working.
> win-x64, linux-x64, linux-musl-x64, osx-x64 and osx-arm64; they are detected and loaded
> automatically on first use — no initialization call needed. If the core is missing for
> your platform, 7z/RAR and the native codecs degrade gracefully; everything else keeps
> working.

## Quick Start

Expand All @@ -44,8 +45,6 @@ Targets `netstandard2.0` and `net8.0`.
```csharp
using GeneralZip;

GeneralZip.Initialize(); // idempotent bootstrap

// Directory → archive (format is chosen by the file extension)
await GeneralZip.CompressAsync(@"C:\data", @"D:\backup.zip");

Expand Down Expand Up @@ -115,10 +114,46 @@ var result = reader.ExtractToDirectory(@"D:\out", new ExtractionOptions
});
```

### High-level operations

```csharp
// Append to an existing archive (read→rewrite; encrypted archives keep their algorithm)
await GeneralZip.AppendAsync("backup.zip", @"C:\new-files");

// Remove entries by exact name
await GeneralZip.RemoveAsync("backup.zip", new[] { "junk.txt" });

// Cross-format conversion (target format from extension)
await GeneralZip.ConvertAsync("old.zip", "new.7z");

// Stream → archive stream and back (no disk involved)
await GeneralZip.CompressAsync(sourceStream, output, "ZIP", "data.bin");

// Parallel extraction & compression (entry-level sharding)
GeneralZip.Extract("huge.zip", "out", extraction: new ExtractionOptions { MaxDegreeOfParallelism = 4 });

// Glob include/exclude filters
GeneralZip.Extract("logs.zip", "out", extraction: new ExtractionOptions
{
IncludePatterns = new[] { "**/*.log" },
ExcludePatterns = new[] { "**/*.tmp" },
});

// Symbolic links & Unix permissions (ZIP/TAR)
writer.AddSymlink("latest.log", "logs/2026.log");
GeneralZip.Extract("pkg.tar", "out", extraction: new ExtractionOptions
{
SymlinkPolicy = SymlinkPolicy.Preserve,
PreserveUnixAttributes = true,
});
```

### Integrity testing

```csharp
var test = GeneralZipReader.Open(path).TestAll();
// Works without a password for plain archives; supply one for encrypted archives
using var testReader = GeneralZipReader.Open(path, o => o.Password = password);
var test = testReader.TestAll();
Console.WriteLine(test.Success ? "OK" : $"{test.FailedCount} entries failed");
```

Expand All @@ -137,16 +172,20 @@ GeneralZip.Encryption.Register(new MyEncryptionProvider());

| Format | Read | Write | Encrypted Read | Encrypted Write |
|---|:---:|:---:|:---:|:---:|
| ZIP (Store/Deflate/Zip64) | ✓ | ✓ | ZipCrypto / WinZip AES / **SM4-GM** | ✓ |
| ZIP (Store/Deflate/**BZip2/Zstd/LZMA**/Zip64) | ✓ | ✓ | ZipCrypto / WinZip AES / **SM4-GM** / **SM2-GM** | ✓ |
| 7z (LZMA2) | ✓ | ✓ | AES-256 | AES-256 |
| RAR4/RAR5 | ✓ | — (proprietary) | ✓ password | — |
| TAR / TAR.GZ | ✓ | ✓ | — | — |
| TAR / TAR.GZ / TAR.BZ2 | ✓ | ✓ | — | — |
| GZ | ✓ (.NET built-in) | ✓ (.NET built-in) | — | — |
| BZ2 / XZ / ZSTD / LZ4 | ✓ (native core) | ✓ (native core) | — | — |
| BZ2 / XZ / ZSTD / LZ4 / BROTLI | ✓ (native core) | ✓ (native core) | — | — |
| CPIO (newc/odc/binary) | ✓ | ✓ (newc) | — | — |
| ISO9660 (+Joliet/Rock Ridge) | ✓ | — (read-only) | — | — |
| CAB | ✓ (NONE/stored) | — (read-only) | — | — |

> 7z/RAR and BZ2/XZ/ZSTD/LZ4 are provided by the **Rust native core** (all pure-Rust crates).
> When the core is missing, the library degrades gracefully: ZIP/TAR/TAR.GZ/GZ (pure managed)
> and all ZIP-family encryption are unaffected.
> 7z/RAR and BZ2/XZ/ZSTD/LZ4/BROTLI are provided by the **Rust native core** (all pure-Rust crates),
> streamed through a callback FFI with no temp files. When the core is missing, the library degrades
> gracefully: ZIP/TAR/CPIO/GZ (pure managed) and all ZIP-family encryption are unaffected.
> ZIP entries can use BZip2/Zstd/LZMA compression methods (interop with 7-Zip/Info-ZIP archives).

**Why some cells are "—":**

Expand Down Expand Up @@ -187,7 +226,8 @@ Place `generalzip_native.dll/.so/.dylib` in one of:
2. `runtimes/<RID>/native/` under the app directory,
3. any path referenced by the `GENERALZIP_NATIVE` environment variable,

then call `GeneralZip.Initialize()` once (already done implicitly by the one-shot APIs).
The core is picked up automatically the first time you use the library — no
initialization call is needed.

## Sample Files

Expand All @@ -208,28 +248,38 @@ Throughput numbers for all formats (including per-algorithm encryption overhead)
| [docs/CRYPTO-SPEC.md](docs/CRYPTO-SPEC.md) | Binary spec of the SM4-GM encrypted ZIP container for third-party interop (Chinese) |
| [docs/BENCHMARKS.md](docs/BENCHMARKS.md) | Full-format performance data (Chinese) |
| [samples/](samples/) | Runnable samples: basic usage, events, benchmarks, fixture generator |
| [fuzz/](fuzz/) | Read-path fuzzing harness (SharpFuzz) + CI robustness regression |

## Project Layout

```
src/GeneralZip/ Library (managed core + bundled Rust native core bindings)
native/generalzip-native/ Rust cdylib: 7z/bzip2/xz/zstd/lz4 codecs (C ABI)
src/GeneralZip.Cli/ gz command line (dotnet tool: `dotnet tool install GeneralZip.Cli`)
native/generalzip-native/ Rust cdylib: 7z/bzip2/xz/zstd/lz4/brotli codecs (C ABI, streaming)
native/dlltool-shim-rs/ Build helper for windows-gnu raw-dylib imports
tests/ 73 tests: standard vectors, interop oracle, events, fixtures
samples/ Samples + sample archives (fixtures)
tests/ 158 tests: standard vectors, interop oracle, events, fixtures, robustness
samples/ Samples + sample archives (fixtures + third-party interop anchors)
fuzz/ Read-path fuzzing harness (SharpFuzz)
build/ One-shot build script
```

## Known Limitations

- RAR is **read-only** — the compression algorithm is proprietary; no compliant implementation can create RAR archives.
- 7z archives cannot be appended to (each write produces a whole new archive).
- SM4-GM is a custom specification (ZIP has no official SM4 standard); interop is limited to this library and third parties implementing the same spec.
- BZ2/XZ/ZSTD/LZ4 require the native core; GZip is always available (pure managed).
- Native zstd compression is a one-shot in-memory API; xz/lz4/bzip2 stream.
- 7z archives cannot be appended in place; Append/Convert use read→rewrite semantics (producing a whole new archive).
- SM4-GM / SM2-GM are custom specifications (ZIP has no official SM standards); interop is limited to this library and third parties implementing the same specs (see `docs/CRYPTO-SPEC.md`).
- BZ2/XZ/ZSTD/LZ4/BROTLI require the native core; GZip is always available (pure managed).
- ISO9660 and CAB are read-only. CAB supports NONE (stored) folders only — MSZIP/LZX/Quantum require a proprietary 32K-window decoder.
- Append/Remove/Convert rewrite the archive: original entry encryption parameters (salt/IV) are regenerated, but the algorithm is preserved automatically.

## Contributing & License

Issues and PRs are welcome. Please run `build\build.ps1` and make sure all tests pass before submitting.

Released under the [MIT License](LICENSE).

<div align="right">

[**English**](README.md) | [中文](README.zh-CN.md)

</div>
Loading