Skip to content

Commit

Permalink
version 22.0 add zstd method to zip fomat
Browse files Browse the repository at this point in the history
  • Loading branch information
jinfeihan57 committed Jul 31, 2022
1 parent 0d9f6a6 commit a1d9de2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CPP/7zip/Archive/Zip/ZipAddCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../../Compress/LzmaEncoder.h"
#include "../../Compress/PpmdZip.h"
#include "../../Compress/XzEncoder.h"
#include "../../Compress/ZstdEncoder.h"

#include "../Common/InStreamWithCRC.h"

Expand Down Expand Up @@ -181,6 +182,7 @@ HRESULT CAddCommon::Set_Pre_CompressionResult(bool inSeqMode, bool outSeqMode, U
case NCompressionMethod::kDeflate: ver = NCompressionMethod::kExtractVersion_Deflate; break;
case NCompressionMethod::kDeflate64: ver = NCompressionMethod::kExtractVersion_Deflate64; break;
case NCompressionMethod::kXz : ver = NCompressionMethod::kExtractVersion_Xz; break;
case NCompressionMethod::kZstd : ver = NCompressionMethod::kExtractVersion_Zstd; break;
case NCompressionMethod::kPPMd : ver = NCompressionMethod::kExtractVersion_PPMd; break;
case NCompressionMethod::kBZip2: ver = NCompressionMethod::kExtractVersion_BZip2; break;
case NCompressionMethod::kLZMA :
Expand Down Expand Up @@ -376,6 +378,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;
Expand Down
32 changes: 31 additions & 1 deletion CPP/7zip/Archive/Zip/ZipHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"

#include "../../Compress/ZstdDecoder.h"

#include "../../Compress/CopyCoder.h"

#ifdef EXTERNAL_CODECS
Expand Down Expand Up @@ -103,7 +105,8 @@ const char * const kMethodNames1[kNumMethodNames1] =

const char * const kMethodNames2[kNumMethodNames2] =
{
"zstd-wz"
// "zstd-wz"
"zstd" // using zstd not zstd-wz to name zip-zstd compress method
, "MP3"
, "xz"
, "Jpeg"
Expand Down Expand Up @@ -794,6 +797,31 @@ 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,
Expand Down Expand Up @@ -1203,6 +1231,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)
Expand Down
2 changes: 1 addition & 1 deletion CPP/7zip/Archive/Zip/ZipHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace NArchive {
namespace NZip {

const unsigned kNumMethodNames1 = NFileHeader::NCompressionMethod::kZstdPk + 1;
const unsigned kMethodNames2Start = NFileHeader::NCompressionMethod::kZstdWz;
const unsigned kMethodNames2Start = NFileHeader::NCompressionMethod::kZstd;
const unsigned kNumMethodNames2 = NFileHeader::NCompressionMethod::kWzAES + 1 - kMethodNames2Start;

extern const char * const kMethodNames1[kNumMethodNames1];
Expand Down
5 changes: 3 additions & 2 deletions CPP/7zip/Archive/Zip/ZipHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ namespace NFileHeader

kTerse = 18,
kLz77 = 19,
kZstdPk = 20,
kZstdPk = 20, // deprecated (use method 93 for zstd)

kZstdWz = 93,
kZstd = 93, // https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
kMP3 = 94,
kXz = 95,
kJpeg = 96,
Expand All @@ -80,6 +80,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
Expand Down

0 comments on commit a1d9de2

Please sign in to comment.