ZStandard support added to zip/zipx (WinZip) and 7zip (mcmilk 7zip)

This commit is contained in:
Nanook 2023-02-02 01:06:18 +00:00
parent b9d019561f
commit 92df1ecd5f
13 changed files with 75 additions and 39 deletions

View file

@ -7,6 +7,7 @@ internal enum ZipCompressionMethod
Deflate64 = 9, Deflate64 = 9,
BZip2 = 12, BZip2 = 12,
LZMA = 14, LZMA = 14,
ZStd = 93,
Xz = 95, Xz = 95,
PPMd = 98, PPMd = 98,
WinzipAes = 0x63 //http://www.winzip.com/aes_info.htm WinzipAes = 0x63 //http://www.winzip.com/aes_info.htm

View file

@ -11,6 +11,7 @@ using SharpCompress.Compressors.LZMA;
using SharpCompress.Compressors.PPMd; using SharpCompress.Compressors.PPMd;
using SharpCompress.Compressors.Xz; using SharpCompress.Compressors.Xz;
using SharpCompress.IO; using SharpCompress.IO;
using ZstdSharp;
namespace SharpCompress.Common.Zip; namespace SharpCompress.Common.Zip;
@ -102,6 +103,10 @@ internal abstract class ZipFilePart : FilePart
{ {
return new XZStream(stream); return new XZStream(stream);
} }
case ZipCompressionMethod.ZStd:
{
return new DecompressionStream(stream);
}
case ZipCompressionMethod.PPMd: case ZipCompressionMethod.PPMd:
{ {
Span<byte> props = stackalloc byte[2]; Span<byte> props = stackalloc byte[2];

View file

@ -7,6 +7,7 @@ using SharpCompress.Compressors.Deflate;
using SharpCompress.Compressors.Filters; using SharpCompress.Compressors.Filters;
using SharpCompress.Compressors.LZMA.Utilites; using SharpCompress.Compressors.LZMA.Utilites;
using SharpCompress.Compressors.PPMd; using SharpCompress.Compressors.PPMd;
using ZstdSharp;
namespace SharpCompress.Compressors.LZMA; namespace SharpCompress.Compressors.LZMA;
@ -20,6 +21,7 @@ internal static class DecoderRegistry
private const uint K_BCJ2 = 0x0303011B; private const uint K_BCJ2 = 0x0303011B;
private const uint K_DEFLATE = 0x040108; private const uint K_DEFLATE = 0x040108;
private const uint K_B_ZIP2 = 0x040202; private const uint K_B_ZIP2 = 0x040202;
private const uint K_ZSTD = 0x4F71101;
internal static Stream CreateDecoderStream( internal static Stream CreateDecoderStream(
CMethodId id, CMethodId id,
@ -52,6 +54,8 @@ internal static class DecoderRegistry
return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false); return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false);
case K_DEFLATE: case K_DEFLATE:
return new DeflateStream(inStreams.Single(), CompressionMode.Decompress); return new DeflateStream(inStreams.Single(), CompressionMode.Decompress);
case K_ZSTD:
return new DecompressionStream(inStreams.Single());
default: default:
throw new NotSupportedException(); throw new NotSupportedException();
} }

View file

@ -1,41 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle> <AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>0.33.0</VersionPrefix> <VersionPrefix>0.33.0</VersionPrefix>
<AssemblyVersion>0.33.0</AssemblyVersion> <AssemblyVersion>0.33.0</AssemblyVersion>
<FileVersion>0.33.0</FileVersion> <FileVersion>0.33.0</FileVersion>
<Authors>Adam Hathcock</Authors> <Authors>Adam Hathcock</Authors>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks> <TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
<AssemblyName>SharpCompress</AssemblyName> <AssemblyName>SharpCompress</AssemblyName>
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly> <SignAssembly>False</SignAssembly>
<PackageId>SharpCompress</PackageId> <PackageId>SharpCompress</PackageId>
<PackageTags>rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz</PackageTags> <PackageTags>rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz</PackageTags>
<PackageProjectUrl>https://github.com/adamhathcock/sharpcompress</PackageProjectUrl> <PackageProjectUrl>https://github.com/adamhathcock/sharpcompress</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>Copyright (c) 2014 Adam Hathcock</Copyright> <Copyright>Copyright (c) 2014 Adam Hathcock</Copyright>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Description>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.</Description> <Description>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.</Description>
<PublishRepositoryUrl>true</PublishRepositoryUrl> <PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols> <IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat> <SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IsTrimmable>true</IsTrimmable> <IsTrimmable>true</IsTrimmable>
</PropertyGroup> <LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup> <PackageReference Include="ZstdSharp.Port" Version="0.6.1" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' "> </ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" /> <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
</ItemGroup> <PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' "> </ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" /> <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.5" /> <PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup> <PackageReference Include="System.Memory" Version="4.5.5" />
<ItemGroup Condition=" '$(VersionlessImplicitFrameworkDefine)' == 'NETFRAMEWORK' "> </ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" /> <ItemGroup Condition=" '$(VersionlessImplicitFrameworkDefine)' == 'NETFRAMEWORK' ">
<PackageReference Include="System.Memory" Version="4.5.5" /> <PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup> <PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>
</Project> </Project>

View file

@ -109,4 +109,27 @@ public class SevenZipArchiveTests : ArchiveTests
//"7Zip.BZip2.split.005", //"7Zip.BZip2.split.005",
//"7Zip.BZip2.split.006", //"7Zip.BZip2.split.006",
//"7Zip.BZip2.split.007" //"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<InvalidOperationException>(
() =>
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"
)
);
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.