diff --git a/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs b/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs index e645035b..13c2dbe7 100644 --- a/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs +++ b/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs @@ -7,6 +7,7 @@ internal enum ZipCompressionMethod Deflate64 = 9, BZip2 = 12, LZMA = 14, + ZStd = 93, Xz = 95, PPMd = 98, WinzipAes = 0x63 //http://www.winzip.com/aes_info.htm diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index f37fc1cd..6f5a73b9 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -11,6 +11,7 @@ using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.PPMd; using SharpCompress.Compressors.Xz; using SharpCompress.IO; +using ZstdSharp; namespace SharpCompress.Common.Zip; @@ -102,6 +103,10 @@ internal abstract class ZipFilePart : FilePart { return new XZStream(stream); } + case ZipCompressionMethod.ZStd: + { + return new DecompressionStream(stream); + } case ZipCompressionMethod.PPMd: { Span props = stackalloc byte[2]; diff --git a/src/SharpCompress/Compressors/LZMA/Registry.cs b/src/SharpCompress/Compressors/LZMA/Registry.cs index 6aba0c5d..3c25ec46 100644 --- a/src/SharpCompress/Compressors/LZMA/Registry.cs +++ b/src/SharpCompress/Compressors/LZMA/Registry.cs @@ -7,6 +7,7 @@ using SharpCompress.Compressors.Deflate; using SharpCompress.Compressors.Filters; using SharpCompress.Compressors.LZMA.Utilites; using SharpCompress.Compressors.PPMd; +using ZstdSharp; namespace SharpCompress.Compressors.LZMA; @@ -20,6 +21,7 @@ internal static class DecoderRegistry private const uint K_BCJ2 = 0x0303011B; private const uint K_DEFLATE = 0x040108; private const uint K_B_ZIP2 = 0x040202; + private const uint K_ZSTD = 0x4F71101; internal static Stream CreateDecoderStream( CMethodId id, @@ -52,6 +54,8 @@ internal static class DecoderRegistry return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false); case K_DEFLATE: return new DeflateStream(inStreams.Single(), CompressionMode.Decompress); + case K_ZSTD: + return new DecompressionStream(inStreams.Single()); default: throw new NotSupportedException(); } diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index c6c2f918..08f0c076 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -1,41 +1,44 @@ - - - SharpCompress - Pure C# Decompression/Compression - en-US - 0.33.0 - 0.33.0 - 0.33.0 - Adam Hathcock - net462;netstandard2.0;netstandard2.1;net6.0;net7.0 - SharpCompress - ../../SharpCompress.snk - true - SharpCompress - rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz - https://github.com/adamhathcock/sharpcompress - MIT - Copyright (c) 2014 Adam Hathcock - false - false - SharpCompress is a compression library for NET Standard 2.0/2.1/NET 6.0/NET 7.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented. - true - true - snupkg - true - + + + SharpCompress - Pure C# Decompression/Compression + en-US + 0.33.0 + 0.33.0 + 0.33.0 + Adam Hathcock + net462;netstandard2.0;netstandard2.1;net6.0;net7.0 + SharpCompress + ../../SharpCompress.snk + False + SharpCompress + rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz + https://github.com/adamhathcock/sharpcompress + MIT + Copyright (c) 2014 Adam Hathcock + false + false + SharpCompress is a compression library for NET Standard 2.0/2.1/NET 6.0/NET 7.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented. + true + true + snupkg + true + latest + True + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index 22d45b2a..1b5848cd 100644 --- a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -109,4 +109,27 @@ public class SevenZipArchiveTests : ArchiveTests //"7Zip.BZip2.split.005", //"7Zip.BZip2.split.006", //"7Zip.BZip2.split.007" + + [Fact] + public void SevenZipArchive_ZSTD_StreamRead() => ArchiveStreamRead("7Zip.ZSTD.7z"); + + [Fact] + public void SevenZipArchive_ZSTD_PathRead() => ArchiveFileRead("7Zip.ZSTD.7z"); + + [Fact] + public void SevenZipArchive_ZSTD_Split() => + Assert.Throws( + () => + ArchiveStreamRead( + null, + "7Zip.ZSTD.Split.7z.001", + "7Zip.ZSTD.Split.7z.002", + "7Zip.ZSTD.Split.7z.003", + "7Zip.ZSTD.Split.7z.004", + "7Zip.ZSTD.Split.7z.005", + "7Zip.ZSTD.Split.7z.006" + ) + ); + + } diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.7z b/tests/TestArchives/Archives/7Zip.ZSTD.7z new file mode 100644 index 00000000..b59cc197 Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.7z differ diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.001 b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.001 new file mode 100644 index 00000000..09ac0007 Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.001 differ diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.002 b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.002 new file mode 100644 index 00000000..85b638bc Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.002 differ diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.003 b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.003 new file mode 100644 index 00000000..84036af2 Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.003 differ diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.004 b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.004 new file mode 100644 index 00000000..656d21c2 Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.004 differ diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.005 b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.005 new file mode 100644 index 00000000..d86eafb1 Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.005 differ diff --git a/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.006 b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.006 new file mode 100644 index 00000000..8a349525 Binary files /dev/null and b/tests/TestArchives/Archives/7Zip.ZSTD.Split.7z.006 differ diff --git a/tests/TestArchives/Archives/WinZip27_ZSTD.zipx b/tests/TestArchives/Archives/WinZip27_ZSTD.zipx new file mode 100644 index 00000000..3e1ad795 Binary files /dev/null and b/tests/TestArchives/Archives/WinZip27_ZSTD.zipx differ