mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-01-31 10:24:13 -06:00
Switch to Zstandard's New advanced API.
- long distance matching is enabled - the compression should improve, the speed also - decompression code is single threaded only
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
#define MY_VER_MAJOR 18
|
#define MY_VER_MAJOR 18
|
||||||
#define MY_VER_MINOR 05
|
#define MY_VER_MINOR 05
|
||||||
#define MY_VER_BUILD 0
|
#define MY_VER_BUILD 0
|
||||||
#define MY_VERSION_NUMBERS "18.05 ZS v1.3.7 R2"
|
#define MY_VERSION_NUMBERS "18.05 ZS v1.3.7 R3"
|
||||||
#define MY_VERSION MY_VERSION_NUMBERS
|
#define MY_VERSION MY_VERSION_NUMBERS
|
||||||
|
|
||||||
#ifdef MY_CPU_NAME
|
#ifdef MY_CPU_NAME
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#define MY_VERSION_CPU MY_VERSION
|
#define MY_VERSION_CPU MY_VERSION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MY_DATE "2018-10-25"
|
#define MY_DATE "2018-10-28"
|
||||||
#undef MY_COPYRIGHT
|
#undef MY_COPYRIGHT
|
||||||
#undef MY_VERSION_COPYRIGHT_DATE
|
#undef MY_VERSION_COPYRIGHT_DATE
|
||||||
#define MY_AUTHOR_NAME "Igor Pavlov, Tino Reichardt"
|
#define MY_AUTHOR_NAME "Igor Pavlov, Tino Reichardt"
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
#define MY_VER_MAJOR 18
|
#define MY_VER_MAJOR 18
|
||||||
#define MY_VER_MINOR 05
|
#define MY_VER_MINOR 05
|
||||||
#define MY_VER_BUILD 0
|
#define MY_VER_BUILD 0
|
||||||
#define MY_VERSION_NUMBERS "1.3.7 R2"
|
#define MY_VERSION_NUMBERS "1.3.7 R3"
|
||||||
#define MY_VERSION MY_VERSION_NUMBERS
|
#define MY_VERSION MY_VERSION_NUMBERS
|
||||||
#define MY_DATE "2018-10-25"
|
#define MY_DATE "2018-10-28"
|
||||||
#undef MY_COPYRIGHT
|
#undef MY_COPYRIGHT
|
||||||
#undef MY_VERSION_COPYRIGHT_DATE
|
#undef MY_VERSION_COPYRIGHT_DATE
|
||||||
#define MY_AUTHOR_NAME "Tino Reichardt"
|
#define MY_AUTHOR_NAME "Tino Reichardt"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ MY_CONSOLE = 1
|
|||||||
CFLAGS = $(CFLAGS)
|
CFLAGS = $(CFLAGS)
|
||||||
|
|
||||||
!IFNDEF UNDER_CE
|
!IFNDEF UNDER_CE
|
||||||
CFLAGS = $(CFLAGS) -DWIN_LONG_PATH -D_7ZIP_LARGE_PAGES -DSUPPORT_DEVICE_FILE
|
CFLAGS = $(CFLAGS) -DWIN_LONG_PATH -D_7ZIP_LARGE_PAGES -DSUPPORT_DEVICE_FILE -DZSTD_MULTITHREAD
|
||||||
!ENDIF
|
!ENDIF
|
||||||
|
|
||||||
|
|
||||||
@@ -318,9 +318,6 @@ ZSTDMT_OBJS = \
|
|||||||
$O\lz5-mt_common.obj \
|
$O\lz5-mt_common.obj \
|
||||||
$O\lz5-mt_compress.obj \
|
$O\lz5-mt_compress.obj \
|
||||||
$O\lz5-mt_decompress.obj \
|
$O\lz5-mt_decompress.obj \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../UI/Console/Console.mak"
|
!include "../../UI/Console/Console.mak"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
PROG = zstd-min.dll
|
PROG = zstd-min.dll
|
||||||
DEF_FILE = ../../Compress/Codec.def
|
DEF_FILE = ../../Compress/Codec.def
|
||||||
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID
|
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID -DZSTD_MULTITHREAD
|
||||||
|
|
||||||
7ZIP_COMMON_OBJS = \
|
7ZIP_COMMON_OBJS = \
|
||||||
$O\StreamUtils.obj \
|
$O\StreamUtils.obj \
|
||||||
@@ -44,9 +44,6 @@ ZSTD_OBJS = \
|
|||||||
$O\zstd_opt.obj \
|
$O\zstd_opt.obj \
|
||||||
|
|
||||||
ZSTDMT_OBJS = \
|
ZSTDMT_OBJS = \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
PROG = zstd.dll
|
PROG = zstd.dll
|
||||||
DEF_FILE = ../../Compress/Codec.def
|
DEF_FILE = ../../Compress/Codec.def
|
||||||
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID -DZSTD_LEGACY_SUPPORT
|
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID -DZSTD_LEGACY_SUPPORT -DZSTD_MULTITHREAD
|
||||||
|
|
||||||
7ZIP_COMMON_OBJS = \
|
7ZIP_COMMON_OBJS = \
|
||||||
$O\StreamUtils.obj \
|
$O\StreamUtils.obj \
|
||||||
@@ -51,9 +51,6 @@ ZSTD_OBJS = \
|
|||||||
$O\zstd_v07.obj \
|
$O\zstd_v07.obj \
|
||||||
|
|
||||||
ZSTDMT_OBJS = \
|
ZSTDMT_OBJS = \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
PROG = 7za.dll
|
PROG = 7za.dll
|
||||||
DEF_FILE = ../../Archive/Archive2.def
|
DEF_FILE = ../../Archive/Archive2.def
|
||||||
CFLAGS = $(CFLAGS)
|
CFLAGS = $(CFLAGS) -DZSTD_LEGACY_SUPPORT -DZSTD_MULTITHREAD
|
||||||
|
|
||||||
COMMON_OBJS = \
|
COMMON_OBJS = \
|
||||||
$O\CRC.obj \
|
$O\CRC.obj \
|
||||||
@@ -240,9 +240,6 @@ ZSTDMT_OBJS = \
|
|||||||
$O\lz5-mt_common.obj \
|
$O\lz5-mt_common.obj \
|
||||||
$O\lz5-mt_compress.obj \
|
$O\lz5-mt_compress.obj \
|
||||||
$O\lz5-mt_decompress.obj \
|
$O\lz5-mt_decompress.obj \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
PROG = 7z.dll
|
PROG = 7z.dll
|
||||||
DEF_FILE = ../../Archive/Archive2.def
|
DEF_FILE = ../../Archive/Archive2.def
|
||||||
CFLAGS = $(CFLAGS) \
|
CFLAGS = $(CFLAGS) -DEXTERNAL_CODECS -DZSTD_LEGACY_SUPPORT -DZSTD_MULTITHREAD
|
||||||
-DEXTERNAL_CODECS -DZSTD_LEGACY_SUPPORT \
|
|
||||||
|
|
||||||
!IFNDEF UNDER_CE
|
!IFNDEF UNDER_CE
|
||||||
CFLAGS = $(CFLAGS) -D_7ZIP_LARGE_PAGES
|
CFLAGS = $(CFLAGS) -D_7ZIP_LARGE_PAGES
|
||||||
@@ -116,9 +115,6 @@ ZSTDMT_OBJS = \
|
|||||||
$O\lz5-mt_common.obj \
|
$O\lz5-mt_common.obj \
|
||||||
$O\lz5-mt_compress.obj \
|
$O\lz5-mt_compress.obj \
|
||||||
$O\lz5-mt_decompress.obj \
|
$O\lz5-mt_decompress.obj \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -116,9 +116,6 @@ ZSTDMT_OBJS = \
|
|||||||
$O\lz5-mt_common.obj \
|
$O\lz5-mt_common.obj \
|
||||||
$O\lz5-mt_compress.obj \
|
$O\lz5-mt_compress.obj \
|
||||||
$O\lz5-mt_decompress.obj \
|
$O\lz5-mt_decompress.obj \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
PROG = 7zu.dll
|
PROG = 7zu.dll
|
||||||
DEF_FILE = ../../Archive/Archive2.def
|
DEF_FILE = ../../Archive/Archive2.def
|
||||||
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID
|
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID -DZSTD_MULTITHREAD
|
||||||
|
|
||||||
COMMON_OBJS = \
|
COMMON_OBJS = \
|
||||||
$O\CRC.obj \
|
$O\CRC.obj \
|
||||||
@@ -232,9 +232,6 @@ ZSTDMT_OBJS = \
|
|||||||
$O\lz5-mt_common.obj \
|
$O\lz5-mt_common.obj \
|
||||||
$O\lz5-mt_compress.obj \
|
$O\lz5-mt_compress.obj \
|
||||||
$O\lz5-mt_decompress.obj \
|
$O\lz5-mt_decompress.obj \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_compress.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -140,27 +140,21 @@ ZSTD_OBJS = \
|
|||||||
$O\debug.obj \
|
$O\debug.obj \
|
||||||
$O\entropy_common.obj \
|
$O\entropy_common.obj \
|
||||||
$O\error_private.obj \
|
$O\error_private.obj \
|
||||||
$O\fse_compress.obj \
|
|
||||||
$O\fse_decompress.obj \
|
$O\fse_decompress.obj \
|
||||||
$O\hist.obj \
|
$O\hist.obj \
|
||||||
$O\huf_compress.obj \
|
|
||||||
$O\huf_decompress.obj \
|
$O\huf_decompress.obj \
|
||||||
$O\pool.obj \
|
$O\pool.obj \
|
||||||
$O\threading.obj \
|
$O\threading.obj \
|
||||||
$O\xxhash.obj \
|
$O\xxhash.obj \
|
||||||
$O\zstd_common.obj \
|
$O\zstd_common.obj \
|
||||||
$O\zstd_compress.obj \
|
|
||||||
$O\zstd_decompress.obj \
|
$O\zstd_decompress.obj \
|
||||||
$O\zstd_double_fast.obj \
|
$O\zstd_double_fast.obj \
|
||||||
$O\zstd_fast.obj \
|
$O\zstd_fast.obj \
|
||||||
$O\zstd_lazy.obj \
|
$O\zstd_lazy.obj \
|
||||||
$O\zstd_ldm.obj \
|
$O\zstd_ldm.obj \
|
||||||
$O\zstdmt_compress.obj \
|
|
||||||
$O\zstd_opt.obj \
|
$O\zstd_opt.obj \
|
||||||
|
|
||||||
ZSTDMT_OBJS = \
|
ZSTDMT_OBJS = \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -159,27 +159,21 @@ ZSTD_OBJS = \
|
|||||||
$O\debug.obj \
|
$O\debug.obj \
|
||||||
$O\entropy_common.obj \
|
$O\entropy_common.obj \
|
||||||
$O\error_private.obj \
|
$O\error_private.obj \
|
||||||
$O\fse_compress.obj \
|
|
||||||
$O\fse_decompress.obj \
|
$O\fse_decompress.obj \
|
||||||
$O\hist.obj \
|
$O\hist.obj \
|
||||||
$O\huf_compress.obj \
|
|
||||||
$O\huf_decompress.obj \
|
$O\huf_decompress.obj \
|
||||||
$O\pool.obj \
|
$O\pool.obj \
|
||||||
$O\threading.obj \
|
$O\threading.obj \
|
||||||
$O\xxhash.obj \
|
$O\xxhash.obj \
|
||||||
$O\zstd_common.obj \
|
$O\zstd_common.obj \
|
||||||
$O\zstd_compress.obj \
|
|
||||||
$O\zstd_decompress.obj \
|
$O\zstd_decompress.obj \
|
||||||
$O\zstd_double_fast.obj \
|
$O\zstd_double_fast.obj \
|
||||||
$O\zstd_fast.obj \
|
$O\zstd_fast.obj \
|
||||||
$O\zstd_lazy.obj \
|
$O\zstd_lazy.obj \
|
||||||
$O\zstd_ldm.obj \
|
$O\zstd_ldm.obj \
|
||||||
$O\zstdmt_compress.obj \
|
|
||||||
$O\zstd_opt.obj \
|
$O\zstd_opt.obj \
|
||||||
|
|
||||||
ZSTDMT_OBJS = \
|
ZSTDMT_OBJS = \
|
||||||
$O\zstd-mt_common.obj \
|
|
||||||
$O\zstd-mt_decompress.obj \
|
|
||||||
$O\zstd-mt_threading.obj \
|
$O\zstd-mt_threading.obj \
|
||||||
|
|
||||||
!include "../../7zip.mak"
|
!include "../../7zip.mak"
|
||||||
|
|||||||
@@ -1,115 +1,53 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (C) 2016 - 2018 Tino Reichardt
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "ZstdDecoder.h"
|
#include "ZstdDecoder.h"
|
||||||
|
|
||||||
int ZstdRead(void *arg, ZSTDCB_Buffer * in)
|
|
||||||
{
|
|
||||||
struct ZstdStream *x = (struct ZstdStream*)arg;
|
|
||||||
size_t size = in->size;
|
|
||||||
|
|
||||||
HRESULT res = ReadStream(x->inStream, in->buf, &size);
|
|
||||||
|
|
||||||
/* catch errors */
|
|
||||||
switch (res) {
|
|
||||||
case E_ABORT:
|
|
||||||
return -2;
|
|
||||||
case E_OUTOFMEMORY:
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* some other error -> read_fail */
|
|
||||||
if (res != S_OK)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
in->size = size;
|
|
||||||
*x->processedIn += size;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ZstdWrite(void *arg, ZSTDCB_Buffer * out)
|
|
||||||
{
|
|
||||||
struct ZstdStream *x = (struct ZstdStream*)arg;
|
|
||||||
UInt32 todo = (UInt32)out->size;
|
|
||||||
UInt32 done = 0;
|
|
||||||
|
|
||||||
while (todo != 0)
|
|
||||||
{
|
|
||||||
UInt32 block;
|
|
||||||
HRESULT res = x->outStream->Write((char*)out->buf + done, todo, &block);
|
|
||||||
|
|
||||||
/* catch errors */
|
|
||||||
switch (res) {
|
|
||||||
case E_ABORT:
|
|
||||||
return -2;
|
|
||||||
case E_OUTOFMEMORY:
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
done += block;
|
|
||||||
if (res == k_My_HRESULT_WritingWasCut)
|
|
||||||
break;
|
|
||||||
/* some other error -> write_fail */
|
|
||||||
if (res != S_OK)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (block == 0)
|
|
||||||
return -1;
|
|
||||||
todo -= block;
|
|
||||||
}
|
|
||||||
|
|
||||||
*x->processedOut += done;
|
|
||||||
/* we need no lock here, cause only one thread can write... */
|
|
||||||
if (x->progress)
|
|
||||||
x->progress->SetRatioInfo(x->processedIn, x->processedOut);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NZSTD {
|
namespace NZSTD {
|
||||||
|
|
||||||
CDecoder::CDecoder():
|
CDecoder::CDecoder():
|
||||||
|
_ctx(NULL),
|
||||||
|
_srcBuf(NULL),
|
||||||
|
_dstBuf(NULL),
|
||||||
|
_srcBufSize(ZSTD_DStreamInSize()),
|
||||||
|
_dstBufSize(ZSTD_DStreamOutSize()),
|
||||||
_processedIn(0),
|
_processedIn(0),
|
||||||
_processedOut(0),
|
_processedOut(0),
|
||||||
_inputSize(0),
|
|
||||||
_numThreads(NWindows::NSystem::GetNumberOfProcessors())
|
_numThreads(NWindows::NSystem::GetNumberOfProcessors())
|
||||||
|
|
||||||
{
|
{
|
||||||
_props.clear();
|
_props.clear();
|
||||||
|
_hMutex = CreateMutex(NULL, FALSE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDecoder::~CDecoder()
|
CDecoder::~CDecoder()
|
||||||
{
|
{
|
||||||
}
|
if (_ctx) {
|
||||||
|
ZSTD_freeDCtx(_ctx);
|
||||||
HRESULT CDecoder::ErrorOut(size_t code)
|
MyFree(_srcBuf);
|
||||||
{
|
MyFree(_dstBuf);
|
||||||
const char *strError = ZSTDCB_getErrorString(code);
|
CloseHandle(_hMutex);
|
||||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
}
|
||||||
|
|
||||||
mbstowcs(wstrError, strError, 200);
|
|
||||||
MessageBoxW(0, wstrError, L"7-Zip Zstandard", MB_ICONERROR | MB_OK);
|
|
||||||
MyFree(wstrError);
|
|
||||||
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte * prop, UInt32 size)
|
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte * prop, UInt32 size)
|
||||||
{
|
{
|
||||||
DProps *pProps = (DProps *)prop;
|
DProps *pProps = (DProps *)prop;
|
||||||
|
|
||||||
if (size != sizeof(DProps))
|
switch (size) {
|
||||||
|
case 3:
|
||||||
|
case 5:
|
||||||
|
memcpy(&_props, pProps, sizeof (DProps));
|
||||||
|
return S_OK;
|
||||||
|
default:
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
|
}
|
||||||
memcpy(&_props, pProps, sizeof (DProps));
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 numThreads)
|
STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 numThreads)
|
||||||
{
|
{
|
||||||
const UInt32 kNumThreadsMax = ZSTDCB_THREAD_MAX;
|
const UInt32 kNumThreadsMax = ZSTD_THREAD_MAX;
|
||||||
if (numThreads < 1) numThreads = 1;
|
if (numThreads < 1) numThreads = 1;
|
||||||
if (numThreads > kNumThreadsMax) numThreads = kNumThreadsMax;
|
if (numThreads > kNumThreadsMax) numThreads = kNumThreadsMax;
|
||||||
_numThreads = numThreads;
|
_numThreads = numThreads;
|
||||||
@@ -132,42 +70,55 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 * outSize)
|
|||||||
HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
|
||||||
ISequentialOutStream * outStream, ICompressProgressInfo * progress)
|
ISequentialOutStream * outStream, ICompressProgressInfo * progress)
|
||||||
{
|
{
|
||||||
ZSTDCB_RdWr_t rdwr;
|
/* 1) create context */
|
||||||
size_t result;
|
if (!_ctx) {
|
||||||
HRESULT res = S_OK;
|
_ctx = ZSTD_createDCtx();
|
||||||
|
if (!_ctx)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
struct ZstdStream Rd;
|
_srcBuf = MyAlloc(_srcBufSize);
|
||||||
Rd.inStream = inStream;
|
if (!_srcBuf)
|
||||||
Rd.processedIn = &_processedIn;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
struct ZstdStream Wr;
|
_dstBuf = MyAlloc(_dstBufSize);
|
||||||
Wr.progress = progress;
|
if (!_dstBuf)
|
||||||
Wr.outStream = outStream;
|
return E_OUTOFMEMORY;
|
||||||
Wr.processedIn = &_processedIn;
|
} else {
|
||||||
Wr.processedOut = &_processedOut;
|
ZSTD_resetDStream(_ctx);
|
||||||
|
|
||||||
/* 1) setup read/write functions */
|
|
||||||
rdwr.fn_read = ::ZstdRead;
|
|
||||||
rdwr.fn_write = ::ZstdWrite;
|
|
||||||
rdwr.arg_read = (void *)&Rd;
|
|
||||||
rdwr.arg_write = (void *)&Wr;
|
|
||||||
|
|
||||||
/* 2) create decompression context */
|
|
||||||
ZSTDCB_DCtx *ctx = ZSTDCB_createDCtx(_numThreads, _inputSize);
|
|
||||||
if (!ctx)
|
|
||||||
return S_FALSE;
|
|
||||||
|
|
||||||
/* 3) decompress */
|
|
||||||
result = ZSTDCB_decompressDCtx(ctx, &rdwr);
|
|
||||||
if (ZSTDCB_isError(result)) {
|
|
||||||
if (result == (size_t)-ZSTDCB_error_canceled)
|
|
||||||
return E_ABORT;
|
|
||||||
return ErrorOut(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 4) free resources */
|
for (;;) {
|
||||||
ZSTDCB_freeDCtx(ctx);
|
size_t size = _srcBufSize;
|
||||||
return res;
|
RINOK(ReadStream(inStream, _srcBuf, &size));
|
||||||
|
for (;;) {
|
||||||
|
ZSTD_inBuffer inBuff = { _srcBuf, size, 0 };
|
||||||
|
ZSTD_outBuffer outBuff= { _dstBuf, _dstBufSize, 0 };
|
||||||
|
size_t const readSizeHint = ZSTD_decompressStream(_ctx, &outBuff, &inBuff);
|
||||||
|
|
||||||
|
if (ZSTD_isError(readSizeHint))
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
/* write decompressed data */
|
||||||
|
RINOK(WriteStream(outStream, _dstBuf, outBuff.pos));
|
||||||
|
WaitForSingleObject(_hMutex, INFINITE);
|
||||||
|
_processedOut += outBuff.pos;
|
||||||
|
RINOK(progress->SetRatioInfo(&_processedIn, &_processedOut));
|
||||||
|
ReleaseMutex(_hMutex);
|
||||||
|
|
||||||
|
if (inBuff.pos > 0) {
|
||||||
|
memmove(_srcBuf, (char*)_srcBuf + inBuff.pos, inBuff.size - inBuff.pos);
|
||||||
|
size = _srcBufSize - inBuff.pos;
|
||||||
|
RINOK(ReadStream(inStream, (char*)_srcBuf + inBuff.pos, &size));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inBuff.size != inBuff.pos)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
/* eof */
|
||||||
|
if (readSizeHint == 0)
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP CDecoder::Code(ISequentialInStream * inStream, ISequentialOutStream * outStream,
|
STDMETHODIMP CDecoder::Code(ISequentialInStream * inStream, ISequentialOutStream * outStream,
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (C) 2016 - 2018 Tino Reichardt
|
||||||
|
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
#include "../../../C/Alloc.h"
|
#include "../../../C/Alloc.h"
|
||||||
#include "../../../C/Threads.h"
|
#include "../../../C/Threads.h"
|
||||||
#include "../../../C/zstd/zstd.h"
|
#include "../../../C/zstd/zstd.h"
|
||||||
#include "../../../C/zstdmt/zstd-mt.h"
|
|
||||||
|
|
||||||
#include "../../Windows/System.h"
|
#include "../../Windows/System.h"
|
||||||
#include "../../Common/Common.h"
|
#include "../../Common/Common.h"
|
||||||
@@ -14,16 +13,20 @@
|
|||||||
#include "../Common/RegisterCodec.h"
|
#include "../Common/RegisterCodec.h"
|
||||||
#include "../Common/ProgressMt.h"
|
#include "../Common/ProgressMt.h"
|
||||||
|
|
||||||
struct ZstdStream {
|
/**
|
||||||
ISequentialInStream *inStream;
|
* possible return values @ 7zip:
|
||||||
ISequentialOutStream *outStream;
|
* S_OK / S_FALSE
|
||||||
ICompressProgressInfo *progress;
|
* E_NOTIMPL
|
||||||
UInt64 *processedIn;
|
* E_NOINTERFACE
|
||||||
UInt64 *processedOut;
|
* E_ABORT
|
||||||
};
|
* E_FAIL
|
||||||
|
* E_OUTOFMEMORY
|
||||||
|
* E_INVALIDARG
|
||||||
|
*/
|
||||||
|
|
||||||
extern int ZstdRead(void *Stream, ZSTDCB_Buffer * in);
|
#define ZSTD_LEVEL_MIN 1
|
||||||
extern int ZstdWrite(void *Stream, ZSTDCB_Buffer * in);
|
#define ZSTD_LEVEL_MAX 22
|
||||||
|
#define ZSTD_THREAD_MAX 128
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NZSTD {
|
namespace NZSTD {
|
||||||
@@ -36,7 +39,7 @@ struct DProps
|
|||||||
memset(this, 0, sizeof (*this));
|
memset(this, 0, sizeof (*this));
|
||||||
_ver_major = ZSTD_VERSION_MAJOR;
|
_ver_major = ZSTD_VERSION_MAJOR;
|
||||||
_ver_minor = ZSTD_VERSION_MINOR;
|
_ver_minor = ZSTD_VERSION_MINOR;
|
||||||
_level = 1;
|
_level = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
Byte _ver_major;
|
Byte _ver_major;
|
||||||
@@ -51,18 +54,21 @@ class CDecoder:public ICompressCoder,
|
|||||||
public CMyUnknownImp
|
public CMyUnknownImp
|
||||||
{
|
{
|
||||||
CMyComPtr < ISequentialInStream > _inStream;
|
CMyComPtr < ISequentialInStream > _inStream;
|
||||||
|
|
||||||
DProps _props;
|
DProps _props;
|
||||||
|
|
||||||
|
ZSTD_DCtx* _ctx;
|
||||||
|
void* _srcBuf;
|
||||||
|
void* _dstBuf;
|
||||||
|
size_t _srcBufSize;
|
||||||
|
size_t _dstBufSize;
|
||||||
|
|
||||||
UInt64 _processedIn;
|
UInt64 _processedIn;
|
||||||
UInt64 _processedOut;
|
UInt64 _processedOut;
|
||||||
UInt32 _inputSize;
|
|
||||||
UInt32 _numThreads;
|
UInt32 _numThreads;
|
||||||
|
HANDLE _hMutex;
|
||||||
|
|
||||||
HRESULT CDecoder::ErrorOut(size_t code);
|
|
||||||
HRESULT CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
|
HRESULT CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
|
||||||
HRESULT SetOutStreamSizeResume(const UInt64 *outSize);
|
HRESULT SetOutStreamSizeResume(const UInt64 *outSize);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
|
MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (C) 2016 - 2018 Tino Reichardt
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "ZstdEncoder.h"
|
#include "ZstdEncoder.h"
|
||||||
@@ -9,31 +15,27 @@ namespace NCompress {
|
|||||||
namespace NZSTD {
|
namespace NZSTD {
|
||||||
|
|
||||||
CEncoder::CEncoder():
|
CEncoder::CEncoder():
|
||||||
|
_ctx(NULL),
|
||||||
|
_srcBuf(NULL),
|
||||||
|
_dstBuf(NULL),
|
||||||
|
_srcBufSize(ZSTD_CStreamInSize()),
|
||||||
|
_dstBufSize(ZSTD_CStreamOutSize()),
|
||||||
_processedIn(0),
|
_processedIn(0),
|
||||||
_processedOut(0),
|
_processedOut(0),
|
||||||
_inputSize(0),
|
|
||||||
_ctx(NULL),
|
|
||||||
_numThreads(NWindows::NSystem::GetNumberOfProcessors())
|
_numThreads(NWindows::NSystem::GetNumberOfProcessors())
|
||||||
{
|
{
|
||||||
_props.clear();
|
_props.clear();
|
||||||
|
_hMutex = CreateMutex(NULL, FALSE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CEncoder::~CEncoder()
|
CEncoder::~CEncoder()
|
||||||
{
|
{
|
||||||
if (_ctx)
|
if (_ctx) {
|
||||||
ZSTDCB_freeCCtx(_ctx);
|
ZSTD_freeCCtx(_ctx);
|
||||||
}
|
MyFree(_srcBuf);
|
||||||
|
MyFree(_dstBuf);
|
||||||
HRESULT CEncoder::ErrorOut(size_t code)
|
CloseHandle(_hMutex);
|
||||||
{
|
}
|
||||||
const char *strError = ZSTDCB_getErrorString(code);
|
|
||||||
wchar_t wstrError[200+5]; /* no malloc here, /TR */
|
|
||||||
|
|
||||||
mbstowcs(wstrError, strError, 200);
|
|
||||||
MessageBoxW(0, wstrError, L"7-Zip Zstandard", MB_ICONERROR | MB_OK);
|
|
||||||
MyFree(wstrError);
|
|
||||||
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARIANT * coderProps, UInt32 numProps)
|
||||||
@@ -54,7 +56,7 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID * propIDs, const PROPVARI
|
|||||||
|
|
||||||
/* level 1..22 */
|
/* level 1..22 */
|
||||||
_props._level = static_cast < Byte > (prop.ulVal);
|
_props._level = static_cast < Byte > (prop.ulVal);
|
||||||
Byte mylevel = static_cast < Byte > (ZSTDCB_LEVEL_MAX);
|
Byte mylevel = static_cast < Byte > (ZSTD_LEVEL_MAX);
|
||||||
if (_props._level > mylevel)
|
if (_props._level > mylevel)
|
||||||
_props._level = mylevel;
|
_props._level = mylevel;
|
||||||
|
|
||||||
@@ -84,52 +86,97 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
|||||||
ISequentialOutStream *outStream, const UInt64 * /*inSize*/ ,
|
ISequentialOutStream *outStream, const UInt64 * /*inSize*/ ,
|
||||||
const UInt64 * /*outSize */, ICompressProgressInfo *progress)
|
const UInt64 * /*outSize */, ICompressProgressInfo *progress)
|
||||||
{
|
{
|
||||||
ZSTDCB_RdWr_t rdwr;
|
ZSTD_EndDirective ZSTD_todo = ZSTD_e_continue;
|
||||||
size_t result;
|
ZSTD_outBuffer outBuff;
|
||||||
HRESULT res = S_OK;
|
ZSTD_inBuffer inBuff;
|
||||||
|
size_t err, srcSize;
|
||||||
|
|
||||||
struct ZstdStream Rd;
|
if (!_ctx) {
|
||||||
Rd.inStream = inStream;
|
_ctx = ZSTD_createCCtx();
|
||||||
Rd.outStream = outStream;
|
if (!_ctx)
|
||||||
Rd.processedIn = &_processedIn;
|
return E_OUTOFMEMORY;
|
||||||
Rd.processedOut = &_processedOut;
|
|
||||||
|
|
||||||
struct ZstdStream Wr;
|
_srcBuf = MyAlloc(_srcBufSize);
|
||||||
if (_processedIn == 0)
|
if (!_srcBuf)
|
||||||
Wr.progress = progress;
|
return E_OUTOFMEMORY;
|
||||||
else
|
|
||||||
Wr.progress = 0;
|
|
||||||
Wr.inStream = inStream;
|
|
||||||
Wr.outStream = outStream;
|
|
||||||
Wr.processedIn = &_processedIn;
|
|
||||||
Wr.processedOut = &_processedOut;
|
|
||||||
|
|
||||||
/* 1) setup read/write functions */
|
_dstBuf = MyAlloc(_dstBufSize);
|
||||||
rdwr.fn_read = ::ZstdRead;
|
if (!_dstBuf)
|
||||||
rdwr.fn_write = ::ZstdWrite;
|
return E_OUTOFMEMORY;
|
||||||
rdwr.arg_read = (void *)&Rd;
|
|
||||||
rdwr.arg_write = (void *)&Wr;
|
|
||||||
|
|
||||||
/* 2) create compression context, if needed */
|
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_compressionLevel, _props._level);
|
||||||
if (!_ctx)
|
if (ZSTD_isError(err)) return E_FAIL;
|
||||||
_ctx = ZSTDCB_createCCtx(_numThreads, _props._level, _inputSize);
|
|
||||||
if (!_ctx)
|
|
||||||
return S_FALSE;
|
|
||||||
|
|
||||||
/* 3) compress */
|
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_nbWorkers, _numThreads);
|
||||||
result = ZSTDCB_compressCCtx(_ctx, &rdwr);
|
if (ZSTD_isError(err)) return E_FAIL;
|
||||||
if (ZSTDCB_isError(result)) {
|
|
||||||
if (result == (size_t)-ZSTDCB_error_canceled)
|
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_contentSizeFlag, 1);
|
||||||
return E_ABORT;
|
if (ZSTD_isError(err)) return E_FAIL;
|
||||||
return ErrorOut(result);
|
|
||||||
|
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_enableLongDistanceMatching, 1);
|
||||||
|
if (ZSTD_isError(err)) return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
for (;;) {
|
||||||
|
|
||||||
|
/* read input */
|
||||||
|
srcSize = _srcBufSize;
|
||||||
|
RINOK(ReadStream(inStream, _srcBuf, &srcSize));
|
||||||
|
|
||||||
|
/* eof */
|
||||||
|
if (srcSize == 0)
|
||||||
|
ZSTD_todo = ZSTD_e_end;
|
||||||
|
|
||||||
|
/* compress data */
|
||||||
|
WaitForSingleObject(_hMutex, INFINITE);
|
||||||
|
_processedIn += srcSize;
|
||||||
|
ReleaseMutex(_hMutex);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
outBuff = { _dstBuf, _dstBufSize, 0 };
|
||||||
|
|
||||||
|
if (ZSTD_todo == ZSTD_e_continue)
|
||||||
|
inBuff = { _srcBuf, srcSize, 0 };
|
||||||
|
else
|
||||||
|
inBuff = { NULL, srcSize, 0 };
|
||||||
|
|
||||||
|
err = ZSTD_compress_generic(_ctx, &outBuff, &inBuff, ZSTD_todo);
|
||||||
|
if (ZSTD_isError(err)) return E_FAIL;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("err=%u ", (unsigned)err);
|
||||||
|
printf("srcSize=%u ", (unsigned)srcSize);
|
||||||
|
printf("todo=%u\n", ZSTD_todo);
|
||||||
|
printf("inBuff.size=%u ", (unsigned)inBuff.size);
|
||||||
|
printf("inBuff.pos=%u\n", (unsigned)inBuff.pos);
|
||||||
|
printf("outBuff.size=%u ", (unsigned)outBuff.size);
|
||||||
|
printf("outBuff.pos=%u\n\n", (unsigned)outBuff.pos);
|
||||||
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* write output */
|
||||||
|
if (outBuff.pos) {
|
||||||
|
RINOK(WriteStream(outStream, _dstBuf, outBuff.pos));
|
||||||
|
WaitForSingleObject(_hMutex, INFINITE);
|
||||||
|
_processedOut += outBuff.pos;
|
||||||
|
RINOK(progress->SetRatioInfo(&_processedIn, &_processedOut));
|
||||||
|
ReleaseMutex(_hMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* done */
|
||||||
|
if (ZSTD_todo == ZSTD_e_end && err == 0)
|
||||||
|
return S_OK;
|
||||||
|
|
||||||
|
/* need more input */
|
||||||
|
if (inBuff.pos == inBuff.size)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
|
||||||
{
|
{
|
||||||
const UInt32 kNumThreadsMax = ZSTDCB_THREAD_MAX;
|
const UInt32 kNumThreadsMax = ZSTD_THREAD_MAX;
|
||||||
if (numThreads < 1) numThreads = 1;
|
if (numThreads < 1) numThreads = 1;
|
||||||
if (numThreads > kNumThreadsMax) numThreads = kNumThreadsMax;
|
if (numThreads > kNumThreadsMax) numThreads = kNumThreadsMax;
|
||||||
_numThreads = numThreads;
|
_numThreads = numThreads;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// (C) 2016 Tino Reichardt
|
// (C) 2016 - 2018 Tino Reichardt
|
||||||
|
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
#include "../../../C/Alloc.h"
|
#include "../../../C/Alloc.h"
|
||||||
#include "../../../C/Threads.h"
|
#include "../../../C/Threads.h"
|
||||||
#include "../../../C/zstd/zstd.h"
|
#include "../../../C/zstd/zstd.h"
|
||||||
#include "../../../C/zstdmt/zstd-mt.h"
|
|
||||||
|
|
||||||
#include "../../Common/Common.h"
|
#include "../../Common/Common.h"
|
||||||
#include "../../Common/MyCom.h"
|
#include "../../Common/MyCom.h"
|
||||||
@@ -41,13 +40,16 @@ class CEncoder:
|
|||||||
{
|
{
|
||||||
CProps _props;
|
CProps _props;
|
||||||
|
|
||||||
|
ZSTD_CCtx* _ctx;
|
||||||
|
void* _srcBuf;
|
||||||
|
void* _dstBuf;
|
||||||
|
size_t _srcBufSize;
|
||||||
|
size_t _dstBufSize;
|
||||||
|
|
||||||
UInt64 _processedIn;
|
UInt64 _processedIn;
|
||||||
UInt64 _processedOut;
|
UInt64 _processedOut;
|
||||||
UInt32 _inputSize;
|
|
||||||
UInt32 _numThreads;
|
UInt32 _numThreads;
|
||||||
|
HANDLE _hMutex;
|
||||||
ZSTDCB_CCtx *_ctx;
|
|
||||||
HRESULT CEncoder::ErrorOut(size_t code);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
|
MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
|
||||||
|
|||||||
Reference in New Issue
Block a user