Merge pull request #140 from fcharlie/master

Add Zstd method to ZIP format.
This commit is contained in:
Tino Reichardt
2020-11-01 10:47:21 +01:00
committed by GitHub
5 changed files with 46 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
#include "../../Compress/LzmaEncoder.h"
#include "../../Compress/PpmdZip.h"
#include "../../Compress/XzEncoder.h"
#include "../../Compress/ZstdEncoder.h"
#include "../Common/InStreamWithCRC.h"
@@ -179,6 +180,7 @@ HRESULT CAddCommon::Set_Pre_CompressionResult(bool inSeqMode, bool outSeqMode, U
case NCompressionMethod::kXz : ver = NCompressionMethod::kExtractVersion_Xz; break;
case NCompressionMethod::kPPMd : ver = NCompressionMethod::kExtractVersion_PPMd; break;
case NCompressionMethod::kBZip2: ver = NCompressionMethod::kExtractVersion_BZip2; break;
case NCompressionMethod::kZstd: ver = NCompressionMethod::kExtractVersion_Zstd; break;
case NCompressionMethod::kLZMA :
{
ver = NCompressionMethod::kExtractVersion_LZMA;
@@ -356,6 +358,12 @@ HRESULT CAddCommon::Compress(
_lzmaEncoder = new CLzmaEncoder();
_compressEncoder = _lzmaEncoder;
}
else if (method == NCompressionMethod::kZstd)
{
_compressExtractVersion = NCompressionMethod::kExtractVersion_Zstd;
NCompress::NZSTD::CEncoder *encoder = new NCompress::NZSTD::CEncoder();
_compressEncoder = encoder;
}
else if (method == NCompressionMethod::kXz)
{
_compressExtractVersion = NCompressionMethod::kExtractVersion_Xz;

View File

@@ -23,6 +23,7 @@
#include "../../Compress/PpmdZip.h"
#include "../../Compress/ShrinkDecoder.h"
#include "../../Compress/XzDecoder.h"
#include "../../Compress/ZstdDecoder.h"
#include "../../Crypto/WzAes.h"
#include "../../Crypto/ZipCrypto.h"
@@ -86,7 +87,9 @@ const char * const kMethodNames1[kNumMethodNames1] =
const char * const kMethodNames2[kNumMethodNames2] =
{
"xz"
"zstd"
, NULL
, "xz"
, "Jpeg"
, "WavPack"
, "PPMd"
@@ -746,6 +749,32 @@ STDMETHODIMP CHandler::Close()
return S_OK;
}
class CZstdDecoder:
public ICompressCoder,
public CMyUnknownImp
{
NCompress::NZSTD::CDecoder *DecoderSpec;
CMyComPtr<ICompressCoder> Decoder;
public:
CZstdDecoder();
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
MY_UNKNOWN_IMP
};
CZstdDecoder::CZstdDecoder()
{
DecoderSpec = new NCompress::NZSTD::CDecoder;
Decoder = DecoderSpec;
}
HRESULT CZstdDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
{
return Decoder->Code(inStream, outStream, NULL, outSize, progress);
}
class CLzmaDecoder:
public ICompressCoder,
@@ -1059,6 +1088,8 @@ HRESULT CZipDecoder::Decode(
lzmaDecoderSpec = new CLzmaDecoder;
mi.Coder = lzmaDecoderSpec;
}
else if (id ==NFileHeader::NCompressionMethod::kZstd)
mi.Coder = new CZstdDecoder();
else if (id == NFileHeader::NCompressionMethod::kXz)
mi.Coder = new NCompress::NXz::CComDecoder;
else if (id == NFileHeader::NCompressionMethod::kPPMd)

View File

@@ -16,7 +16,7 @@ namespace NArchive {
namespace NZip {
const unsigned kNumMethodNames1 = NFileHeader::NCompressionMethod::kLZMA + 1;
const unsigned kMethodNames2Start = NFileHeader::NCompressionMethod::kXz;
const unsigned kMethodNames2Start = NFileHeader::NCompressionMethod::kZstd;
const unsigned kNumMethodNames2 = NFileHeader::NCompressionMethod::kWzAES + 1 - kMethodNames2Start;
extern const char * const kMethodNames1[kNumMethodNames1];
@@ -74,7 +74,7 @@ private:
m_WriteNtfsTimeExtra = true;
_removeSfxBlock = false;
m_ForceLocal = false;
m_ForceUtf8 = false;
m_ForceUtf8 = true;
_forceCodePage = false;
_specifiedCodePage = CP_OEMCP;
}

View File

@@ -57,6 +57,7 @@ namespace NFileHeader
kTerse = 18,
kLz77 = 19,
kZstd = 93,
kXz = 95,
kJpeg = 96,
kWavPack = 97,
@@ -77,6 +78,7 @@ namespace NFileHeader
const Byte kExtractVersion_LZMA = 63;
const Byte kExtractVersion_PPMd = 63;
const Byte kExtractVersion_Xz = 20; // test it
const Byte kExtractVersion_Zstd = 20; // WinZip mark it
}
namespace NExtraID

View File

@@ -223,7 +223,8 @@ static const EMethodID g_ZipMethods[] =
kDeflate64,
kBZip2,
kLZMA,
kPPMdZip
kPPMdZip,
kZSTD
};
static const EMethodID g_GZipMethods[] =