This document provides a high-level introduction to GrindCore.SharpCompress, explaining its purpose, architecture, capabilities, and key differentiators from the original SharpCompress library. This overview covers the project's structure, supported formats and frameworks, and the native compression integration that provides significant performance improvements.
For detailed information about specific subsystems:
GrindCore.SharpCompress is an enhanced fork of the SharpCompress library that integrates GrindCore native compression technology to provide substantial performance improvements while maintaining 100% API compatibility with the original library. The project serves as a drop-in replacement for SharpCompress, requiring no code changes for existing applications.
Sources: README.md1-8 src/SharpCompress/SharpCompress.csproj1-20
| Aspect | Original SharpCompress | GrindCore.SharpCompress |
|---|---|---|
| Compression Implementation | Pure managed C# | Native C via GrindCore + managed C# |
| Performance | Standard managed performance | 3-5x faster for major algorithms |
| Deflate/GZip | Managed implementation | Native ZLib-NG v2.2.1 |
| LZMA/LZMA2 | Managed implementation | Native LZMA v25.1.0 |
| ZStandard | Managed implementation | Native ZStandard v1.5.7 |
| LZ4 | Not available | Native LZ4 v1.10.0 |
| Brotli | Not available | Native Brotli v1.1.0 |
| AOT Compatibility | Limited | Full support for .NET 8+ |
| API Compatibility | N/A | 100% compatible |
Sources: README.md25-32 README.md108-125
GrindCore.SharpCompress uses the System.IO.Compression pattern to provide native compression streams that integrate seamlessly with .NET's standard stream abstractions. This approach:
Sources: README.md15-24
Diagram: System Architecture with Code Entities
This diagram shows the major components and their relationships, using actual class names from the codebase. The system is organized in layers:
Sources: README.md132-171 src/SharpCompress/SharpCompress.csproj1-137
The library provides comprehensive support for multiple archive formats with varying capabilities:
| Format | Read | Write | Native Performance | Encryption Support | Special Features |
|---|---|---|---|---|---|
| ZIP | ✅ | ✅ | ✅ (Deflate) | PKWARE, WinZip AES | Zip64, modifications |
| TAR | ✅ | ✅ | ✅ (with compression) | N/A | POSIX/GNU/BSD headers |
| GZIP | ✅ | ✅ | ✅ | N/A | Single-entry format |
| RAR | ✅ | ❌ | N/A | RAR encryption | Solid archives, multi-volume |
| 7-Zip | ✅ | ❌ | N/A | AES-256 | Solid archives, BCJ filters |
| LZMA/XZ | ✅ | ✅ | ✅ | N/A | Block and Solid modes |
| ZSTD | ✅ | ✅ | ✅ | N/A | 22 compression levels |
| LZ4 | ✅ | ✅ | ✅ | N/A | 12 compression levels |
| BROTLI | ✅ | ✅ | ✅ | N/A | 11 compression levels |
| BZIP2 | ✅ | ✅ | ❌ (managed) | N/A | Original C# implementation |
Note: RAR and 7-Zip are read-only due to proprietary format restrictions. Legacy formats like Shrink, Implode, Reduce, PPMd, and ARJ are also supported for reading.
Sources: README.md58-78
Diagram: Framework and Platform Targeting Strategy
The project targets 8 different frameworks from a single codebase using conditional compilation:
Platform-specific native binaries are automatically selected at runtime based on the operating system and architecture.
Sources: src/SharpCompress/SharpCompress.csproj11 src/SharpCompress/SharpCompress.csproj31-37 README.md180-188
The build system uses two key preprocessor symbols:
GRINDCORE: Defined when UseGrindCore MSBuild property is true (default). Includes native compression stream wrappers and excludes managed implementations.LEGACY_DOTNET: Defined for .NET Framework 4.8/4.8.1 and .NET Standard 2.0. Enables compatibility code and polyfills.Sources: src/SharpCompress/SharpCompress.csproj38-45 src/SharpCompress/SharpCompress.csproj31-33
The native integration is the library's primary differentiator, implemented through conditional compilation:
Diagram: Native Integration Compilation Flow
When UseGrindCore=true (the default):
GRINDCORE preprocessor symbol is defined*_GC.cs) are included in compilationGrindCore NuGet package (v0.7.0) is referencedWhen UseGrindCore=false:
GRINDCORE symbol is not definedSources: src/SharpCompress/SharpCompress.csproj38-76 src/SharpCompress/SharpCompress.csproj78-128 src/SharpCompress/SharpCompress.csproj130-133
The dependency graph varies by target framework and build configuration:
| Dependency | Condition | Purpose |
|---|---|---|
| GrindCore (0.7.0) | When UseGrindCore=true | Native compression implementations |
| Microsoft.Bcl.AsyncInterfaces (10.0.3) | Legacy frameworks | Async interface polyfills |
| System.Text.Encoding.CodePages (10.0.3) | Legacy frameworks | Character encoding support |
| System.Buffers (4.6.1) | Legacy frameworks | Span and Memory support |
| System.Memory (4.6.3) | Legacy frameworks | Modern memory APIs |
| Microsoft.NET.ILLink.Tasks (10.0.3) | .NET 8+ | Trimming and AOT support |
Sources: src/SharpCompress/packages.lock.json1-627 Directory.Packages.props1-28
The library is organized into several major subsystems, each documented in detail in separate wiki pages:
ArchiveFactory: Static factory methods for opening archives with random access (Archive Format Support)ReaderFactory: Static factory methods for sequential streaming reads (Reading Archives)WriterFactory: Static factory methods for creating new archives (Writing Archives)ZipArchive, ZipReader, ZipWriter - Full read/write support with encryption (ZIP Format)RarArchive, RarReader - Read-only with solid archive support (RAR Format)SevenZipArchive - Read-only with LZMA2 and filters (7-Zip Format)TarArchive, TarReader, TarWriter - POSIX/GNU/BSD header support (TAR Format)GZipArchive, BZip2Archive, LZipArchive, XZArchive (GZip and Single-File Formats)SharpCompressStream: Intelligent buffering with passthrough/buffered modes (Stream Infrastructure)RingBuffer: Circular buffer enabling limited backward seeking on non-seekable streamsReadOnlySubStream: Enforces entry boundaries during extractionGRINDCORE defined): DeflateStream_GC, GZipStream_GC, LzmaStream_GC, ZStandardStream_GC, LZ4Stream_GC, BrotliStream_GC (Native Compression Streams)BZip2Stream, LZipStream, PPMdStream, legacy algorithms (Managed Compression Implementations)Sources: src/SharpCompress/SharpCompress.csproj60-76 src/SharpCompress/SharpCompress.csproj78-128
The project uses a custom build system defined in build/Program.cs with targets for:
The build process is automated via GitHub Actions for continuous integration.
For detailed information about the build pipeline, code formatting standards, and development workflow, see Build Pipeline and Automation.
Sources: build/build.csproj1-12
All library-specific exceptions inherit from SharpCompressException, enabling unified error handling:
Diagram: Exception Hierarchy
This design allows client code to catch all library exceptions with a single catch (SharpCompressException) block while still enabling specific exception handling when needed.
Sources: tests/SharpCompress.Test/ExceptionHierarchyTests.cs10-116
| Property | Value |
|---|---|
| Package ID | GrindCore.SharpCompress |
| Assembly Name | GrindCore.SharpCompress.dll |
| Authors | Adam Hathcock (original), Nanook (GrindCore integration) |
| License | MIT |
| Repository | https://github.com/Nanook/GrindCore.SharpCompress |
| Strong Named | Yes (signed with SharpCompress.snk) |
| NuGet Command | Install-Package GrindCore.SharpCompress |
Sources: src/SharpCompress/SharpCompress.csproj3-19 README.md99-106
Refresh this wiki