Skip to content

Move ZstdSharp into SharpCompress - Complete Integration#1052

Merged
adamhathcock merged 35 commits intomasterfrom
copilot/move-zstdsharp-into-sharpcompress
Dec 18, 2025
Merged

Move ZstdSharp into SharpCompress - Complete Integration#1052
adamhathcock merged 35 commits intomasterfrom
copilot/move-zstdsharp-into-sharpcompress

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

Completes the full integration of ZstdSharp directly into SharpCompress, removing the external ZstdSharp.Port dependency (addresses #1030, started in #949).

Overview

This PR integrates all ~217 ZstdSharp implementation files into SharpCompress, providing a fully self-contained ZStandard compression/decompression implementation without external dependencies.

Changes Made

Core Infrastructure

  • CLSCompliant(false): Required for unsafe pointer usage in ZStandard internals
  • Error Handling: ZSTD_ErrorCode enum, ZstdException class, ThrowHelper with extension methods
  • Memory Management: UnsafeHelper with malloc, calloc, free, memcpy, memset, memmove, memcmp
  • Buffer Types: ZSTD_inBuffer_s, ZSTD_outBuffer_s, ZSTD_customMem
  • Parameter Types: Compression (ZSTD_cParameter, ZSTD_compressionParameters, ZSTD_strategy) and decompression (ZSTD_dParameter) parameters
  • Frame Types: ZSTD_frameType_e, ZSTD_frameHeader, ZSTD_frameParameters, ZSTD_parameters
  • Dictionary Types: ZSTD_dictContentType_e, ZSTD_dictLoadMethod_e
  • Directives: ZSTD_EndDirective, ZSTD_ResetDirective

Complete Unsafe Implementation (~217 files)

  • Methods Partial Class: ErrorPrivate, Mem (I/O API), Bits, Compiler, Allocations, ZstdCommon
  • FSE (Finite State Entropy): Compression and decompression algorithms (Fse.cs, FseCompress.cs, FseDecompress.cs)
  • Huffman Encoding: Compression and decompression (Huf.cs, HufCompress.cs, HufDecompress.cs)
  • Dictionary Training: COVER and FastCover algorithms (Cover.cs, Fastcover.cs, Zdict.cs)
  • Core Algorithms:
    • Compression: ZstdCompress.cs, ZstdCompressInternal.cs, ZstdCompressLiterals.cs, ZstdCompressSequences.cs, ZstdCompressSuperblock.cs
    • Decompression: ZstdDecompress.cs, ZstdDecompressBlock.cs, ZstdDecompressInternal.cs
    • Strategy implementations: ZstdFast.cs, ZstdDoubleFast.cs, ZstdLazy.cs, ZstdOpt.cs
    • Long-distance matching: ZstdLdm.cs
  • Entropy Coding: EntropyCommon.cs, Bitstream.cs
  • Context Management: ZSTD_CCtx_s.cs, ZSTD_DCtx_s.cs, compression/decompression context structures
  • Multithreading: ZstdmtCompress.cs, Pool.cs
  • XXHash: Xxhash.cs for checksums
  • Supporting Data Structures: 200+ struct and enum definitions

High-Level API

  • Decompressor: Public API for decompression with Unwrap() methods and dictionary support
  • Compressor: Public API for compression with Wrap() methods
  • DecompressionStream and CompressionStream: Stream-based APIs
  • SafeHandles: SafeCctxHandle and SafeDctxHandle for safe resource management
  • Supporting Classes: JobThreadPool, SynchronizationWrapper, UnmanagedObject, Constants, BitOperations

Dependency Removal

  • Removed ZstdSharp.Port package reference from SharpCompress.csproj
  • Updated all ZstdSharp usages to internal classes:
    • Common/Zip/ZipFilePart.cs: Changed namespace from ZstdSharp to SharpCompress.Compressors.ZStandard
    • Compressors/LZMA/Registry.cs: Updated namespace usage
    • Writers/Zip/ZipWriter.cs: Changed new ZstdSharp.CompressionStream(...) to new CompressionStream(...)

Bug Fixes and Improvements

  • Fixed obsolete API: Thread.VolatileReadVolatile.Read in ZstdDecompressBlock.cs
  • Cleaned up unused using statements in ZstandardConstants.cs
  • Rebased onto latest master (394fd2e) for CSharpier 1.2.3 and other updates

Build Status

✅ Project builds successfully on all targets (net48, net8.0, net10.0)
✅ No warnings or errors
✅ No external ZstdSharp dependency required
✅ Code formatted with CSharpier 1.2.3

Files Changed

  • 224 files added: Complete ZstdSharp implementation
  • 3 files modified: Namespace updates to remove ZstdSharp.Port references
  • 1 file modified: Package reference removal from .csproj

SharpCompress now has a complete, self-contained ZStandard implementation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Move ZstdSharp into SharpCompress</issue_title>
<issue_description>think the authors have little interest in this: oleg-st/ZstdSharp#36

The biggest hurdle found so far is that there is a lot of unsafe/native usage that is probably incompatible with AOT. I know work was done to make everything CLSCompliant.

I'm ignoring big issues but might also rethink what targets there are. The legacy framework targets are slowing things down too.

Started here #949</issue_description>

<agent_instructions>Make a start but there are a lot of changes needed to the code then stop and saw progress</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 29, 2025
Copilot AI and others added 2 commits November 29, 2025 13:11
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot AI changed the title [WIP] Move ZstdSharp into SharpCompress Move ZstdSharp into SharpCompress - Initial Infrastructure Nov 29, 2025
Copilot AI requested a review from adamhathcock November 29, 2025 13:17
@adamhathcock
Copy link
Owner

@copilot keep going

…afe Methods

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 29, 2025

@copilot keep going

Added significant infrastructure in commit 4021208:

  • UnsafeHelper with memory management utilities (malloc, calloc, free, memcpy, memset, memmove, memcmp)
  • ThrowHelper for error handling with extension methods
  • Core Methods partial class with: ErrorPrivate, Mem (I/O API), Bits, Compiler, Allocations, ZstdCommon

The project now builds successfully with these foundational types. Continuing to add more files...

Copilot AI and others added 2 commits November 29, 2025 13:34
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
@adamhathcock
Copy link
Owner

@copilot update from the latest master and move to the next step

Copilot AI and others added 12 commits December 18, 2025 12:30
- Updated SharpCompress.csproj target frameworks from net48;net481;netstandard2.0;net6.0;net8.0 to net48;net481;netstandard2.0;net8.0;net10.0
- Updated test and build projects to use .NET 10
- Updated global.json to .NET 10 SDK
- Updated CI workflow to use .NET 10
- Fixed deprecated Rfc2898DeriveBytes constructor for .NET 10 (SYSLIB0060)
- Updated package description and README to reflect new supported frameworks
- Updated package versions for .NET 10 compatibility

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
- Updated target frameworks to net48;net8.0;net10.0 only
- Removed netstandard2.0 and net481 package conditions
- Updated conditional compilation to use NETFRAMEWORK only
- Updated package description and README

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
…dling

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…xplicit DirectoryEntry case

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move ZstdSharp into SharpCompress

3 participants

Comments