7Zip 不支持流式格式,需随机访问;RAR 为专有格式且压缩闭源,仅支持解压;默认 Deflate 压缩输出缓冲区改为 64 KiB,每个活跃压缩器多占 48 KiB 内存
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.
dotnet add package SharpCompressREADME 未说明,纯托管 C# 库,无 GPU 或特殊硬件要求
纯 C# 压缩库,支持多种格式解压与部分格式写入,可流式处理大文件
纯 C# 实现的压缩解压库,支持 7zip、rar、tar、gzip、bzip2、xz 等多种格式,无需依赖原生库即可在 .NET 项目中读写压缩包。
核心能力
- 支持 unrar、un7zip、unzip、untar 等十余种格式解压
- 支持 zip、tar、bzip2、gzip、lzip、zstandard 流写入
- 支持非可寻址流,边下载边解压大文件
- 所有 I/O 操作支持 async/await 异步读写
- 可通过 Providers 注册表替换内置压缩编解码器
容易踩的坑
- 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
- 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.PasswordandEncryptHeader. - ZIP64 streaming output: ZIP64 archives can now be written to non-seekable streams. Enable
ZipWriterOptions.UseZip64before 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.EnableParallelismfor 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
ArchiveFactoryare now obsolete in favor ofArchiveDetector; file-path extraction is available throughArchiveExtractor.WriteToDirectory. -
Custom
IReaderOptionsandIWriterOptionsimplementations must provideEnableParallelism. -
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
- Generate the synchronous archive entry extensions from the async ones by @virzak in https://github.com/adamhathcock/sharpcompress/pull/1381
- Update Zomp.SyncMethodGenerator to 2.0.42 by @virzak in https://github.com/adamhathcock/sharpcompress/pull/1382
- Use more Sync Generator by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1383
- Updates recommended by 5.6 Sol by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1380
- Improve LZMA decoding for Solid Archives by @julianxhokaxhiu in https://github.com/adamhathcock/sharpcompress/pull/1388
- Honor cancellation in BufferedSubStream async cached-read fast paths by @adamhathcock with @Copilot in https://github.com/adamhathcock/sharpcompress/pull/1389
- Improve CRC32 by using the slice-by-16 optimization by @julianxhokaxhiu in https://github.com/adamhathcock/sharpcompress/pull/1398
- gzip using sync generator by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1400
- Add LZMA Parallelism and Fast Decoder for modern dotnet by @julianxhokaxhiu in https://github.com/adamhathcock/sharpcompress/pull/1399
- Use Sync Method Generator for zip items by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1401
- Fix TarFactory.cs formatting to unblock CI by @adamhathcock with @Copilot in https://github
- 7z password-protected writing: Added AES-256 encryption for LZMA/LZMA2 archives, including optional header encryption to hide filenames and metadata through
- 0.50.70.50.7 - another allocation fix最新正式版2026-10-20 · 2026-10-20 10:29 UTC
What's Changed
- Reduce allocations in RAR5 password key derivation by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1464
Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.50.6...0.50.7
- 0.50.60.50.6 - fixes and memory improvements2026-10-19 · 2026-10-19 10:06 UTC
查看更新说明
What's Changed
- Fix 7z encryption detection for streamless files by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1446
- pr 1436 followups by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1442
- Expose public exceptions for encrypted 7z decoding failures by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1445
- Fix empty and directory-only 7z archive finalization by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1444
- Fix pooled buffer ownership and exception-safe cleanup by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1447
- Fix 7z writer attribute interoperability with libarchive by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1443
- fixes for release by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1458
Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.50.5...0.50.6
- 0.50.50.50.5 - more fixes galore2026-10-09 · 2026-10-09 14:14 UTC
查看更新说明
What's Changed
- Cache RAR5 encrypted header key derivation by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1419
- Update .NET SDK and SourceLink to fix NuGet auditing by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1421
- Fix encrypted RAR5 archive comments by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1420
- Reuse RAR5 derived keys across encrypted file entries by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1426
- Reapply uppercase split ZIP parts fix to release by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1431
- Reapply gzip FEXTRA XLEN overflow fix to release by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1433
- Reapply encrypted RAR header rescan fix to release by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1432
- Reapply gzip reader/archive XLEN overflow fix to release by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1434
- Reapply 7z next-header bounds validation to release by @adamhathcock in https://github.com/adamhathcock/sharpcompress/pull/1435
Full Changelog: https://github.com/adamhathcock/sharpcompress/compare/0.50.4...0.50.5
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
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.
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.