sharpcompress

adamhathcockMIT活跃维护

纯 C# 实现的压缩解压库,支持 7zip、rar、tar、gzip、bzip2、xz 等多种格式,无需依赖原生库即可在 .NET 项目中读写压缩包。

SharpCompress is a fully managed C# library to deal with many compression types and formats.

0.50.7发布于 2026-10-20 10:29 UTC2,594star524fork同步于 2026-11-10 17:45 UTC

怎么上手

由 README 提炼,执行前请确认
dotnet add package SharpCompress
硬件要求按 README 说明

README 未说明,纯托管 C# 库,无 GPU 或特殊硬件要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

纯 C# 压缩库,支持多种格式解压与部分格式写入,可流式处理大文件

纯 C# 实现的压缩解压库,支持 7zip、rar、tar、gzip、bzip2、xz 等多种格式,无需依赖原生库即可在 .NET 项目中读写压缩包。

核心能力

  • 支持 unrar、un7zip、unzip、untar 等十余种格式解压
  • 支持 zip、tar、bzip2、gzip、lzip、zstandard 流写入
  • 支持非可寻址流,边下载边解压大文件
  • 所有 I/O 操作支持 async/await 异步读写
  • 可通过 Providers 注册表替换内置压缩编解码器

容易踩的坑

7Zip 不支持流式格式,需随机访问;RAR 为专有格式且压缩闭源,仅支持解压;默认 Deflate 压缩输出缓冲区改为 64 KiB,每个活跃压缩器多占 48 KiB 内存

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本0.50.7
  1. 0.51.0-beta2pre-release2026-10-26 · 2026-10-26 16:50 UTC
    查看更新说明

    Just adjustment of a pre-release on GitHub actions

    Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.51.0-beta1...0.51.0-beta2

  2. 0.51.0-beta10.51.0-beta1 - the next onepre-release2026-10-26 · 2026-10-26 16:41 UTC
    查看更新说明

    Highlights

    • 7z password-protected writing: Added AES-256 encryption for LZMA/LZMA2 archives, including optional header encryption to hide filenames and metadata through SevenZipWriterOptions.Password and EncryptHeader.
    • ZIP64 streaming output: ZIP64 archives can now be written to non-seekable streams. Enable ZipWriterOptions.UseZip64 before writing potentially large entries.
    • Improved archive detection and inspection: New APIs distinguish lightweight format detection from detailed metadata inspection, including compression wrappers, encryption, solid streams, entry counts, and incomplete metadata.
    • Optional parallel decoding: Added ReaderOptions.EnableParallelism for eligible 7z LZMA2 decoding and ahead-of-time WinZip AES key derivation.

    Performance

    • Reduced allocations across ZIP, RAR, 7z, TAR, and XZ through pooled buffers, reusable decoder workspaces, and fewer intermediate copies.
    • Improved LZMA/LZMA2 decoding, including a fast decoder on modern .NET and faster processing of asynchronously buffered chunks.
    • Optimized Deflate, CRC32 calculations, WinZip AES reading, and encrypted 7z writing.
    • Added native memory-based async reads through XZ filter chains on .NET 6 and later.

    Fixes

    • Fixed reading encrypted ZIP entries that use data descriptors and corrected ZIP64 descriptor-width handling.
    • Fixed XZ BCJ decoding across read boundaries.
    • Fixed encrypted 7z entries reporting their compression method.
    • Improved async RAR checksum validation and handling of empty reads and entries without checksums.
    • Hardened LZMA dictionary bounds checking for malformed input.
    • Fixed pooled-buffer cleanup, partial-read disposal, TAR probing, and ownership of borrowed archive streams.
    • Improved async writable-entry streams and resource disposal across supported frameworks.

    Upgrade Notes

    • Breaking API change: Replaced ArchiveFactory.GetArchiveInformation[Async] with:

      • ArchiveDetector.DetectArchive[Async] for format and API availability.
      • ArchiveInspector.InspectArchive[Async] for detailed metadata.

      These APIs and their result types are in SharpCompress.Detection.

    • Detection helpers on ArchiveFactory are now obsolete in favor of ArchiveDetector; file-path extraction is available through ArchiveExtractor.WriteToDirectory.

    • Custom IReaderOptions and IWriterOptions implementations must provide EnableParallelism.

    • The default Deflate provider compression-output buffer increased from 16 KiB to 64 KiB, adding 48 KiB per active compressor. Decompression buffer defaults are unchanged.

    What's Changed

  3. 0.50.70.50.7 - another allocation fix最新正式版2026-10-20 · 2026-10-20 10:29 UTC

    What's Changed

    Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.50.6...0.50.7

  4. 0.50.60.50.6 - fixes and memory improvements2026-10-19 · 2026-10-19 10:06 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.50.5...0.50.6

  5. 0.50.50.50.5 - more fixes galore2026-10-09 · 2026-10-09 14:14 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.50.4...0.50.5

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    SharpCompress

    SharpCompress is a compression library in pure C# for .NET Framework 4.8, .NET Standard 2.0/2.1, .NET 6.0, .NET 8.0, and .NET 10.0 that can unrar, un7zip, unzip, untar, unbzip2, ungzip, unlzip, unxz, unzstd, unarc, unarj, unace, and unlzw with forward-only reading and file random access APIs. Write support for zip, tar, bzip2, gzip, lzip, zstandard compression streams, and 7zip archives is implemented.

    The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream).

    NEW: All I/O operations now support async/await for improved performance and scalability. See the USAGE.md for examples.

    GitHub Actions Build - SharpCompress Static Badge

    Need Help?

    Post Issues on Github!

    Check the Supported Formats, API Reference, and Basic Usage.

    Custom Compression Providers

    If you need to swap out SharpCompress’s built-in codecs, the Providers property (and WithProviders(...) extensions) on ReaderOptions and WriterOptions lets you supply a CompressionProviderRegistry. The selected registry is used by Reader/Writer APIs, Archive APIs, and async extraction paths, so the same provider choice is applied consistently across open/read/write flows. The default registry is already wired up, so customization is only necessary when you want to plug in alternatives such as SystemGZipCompressionProvider or a third-party CompressionProvider. See docs/USAGE.md#custom-compression-providers for guided examples.

    Recommended Formats

    In general, I recommend GZip (Deflate)/BZip2 (BZip)/LZip (LZMA) as the simplicity of the formats lend to better long term archival as well as the streamability. Tar is often used in conjunction for multiple files in a single archive (e.g. .tar.gz)

    Zip is okay, but it's a very hap-hazard format and the variation in headers and implementations makes it hard to get correct. Uses Deflate by default but supports a lot of compression methods.

    RAR is not recommended as it's a proprietary format and the compression is closed source. Use Tar/LZip for LZMA

    7Zip and XZ both are overly complicated. 7Zip does not support streamable formats. XZ has known holes explained here: (http://www.nongnu.org/lzip/xz_inadequate.html) Use Tar/LZip for LZMA compression instead.

    ZStandard is an efficient format that works well for streaming with a flexible compression level to tweak the speed/performance trade off you are looking for.

    A Simple Request

    Hi everyone. I hope you're using SharpCompress and finding it useful. Please give me feedback on what you'd like to see changed especially as far as usability goes. New feature suggestions are always welcome as well. I would also like to know what projects SharpCompress is being used in. I like seeing how it is used to give me ideas for future versions. Thanks!

    Please do not email me directly to ask for help. If you think there is a real issue, please report it here.

    Want to contribute?

    I'm always looking for help or ideas. Please submit code or email with ideas. Unfortunately, just letting me know you'd like to help is not enough because I really have no overall plan of what needs to be done. I'll definitely accept code submissions and add you as a member of the project!

    Notes

    The default DeflateCompressionProvider now uses a 64 KiB compression-output buffer (previously 16 KiB) to reduce downstream writes. This adds 48 KiB per active compressor. Decompression buffers and directly constructed DeflateStream defaults remain unchanged at 16 KiB.

    XZ implementation based on: https://github.com/sambott/XZ.NET by @sambott

    XZ BCJ filters support contributed by Louis-Michel Bergeron, on behalf of aDolus Technology Inc. - 2022

    7Zip implementation based on: https://code.google.com/p/managed-lzma/

    Zstandard implementation from: https://github.com/oleg-st/ZstdSharp

    LICENSE Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.