Skip to content

Commit

Permalink
Add NanaZipCodecsLizardDecode, NanaZipCodecsLz4Decode and NanaZipCode…
Browse files Browse the repository at this point in the history
…csLz5Decode.
  • Loading branch information
MouriNaruto committed Nov 4, 2024
1 parent 4fca1ae commit 8c42b78
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 90 deletions.
35 changes: 35 additions & 0 deletions NanaZip.Codecs/NanaZip.Codecs.MultiThreadWrapper.LZ4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "NanaZip.Codecs.MultiThreadWrapper.LZ4.h"

#include <cstddef>

EXTERN_C int NanaZipCodecsLz4Read(
void* Context,
LZ4MT_Buffer* Input)
Expand All @@ -35,3 +37,36 @@ EXTERN_C int NanaZipCodecsLz4Write(
reinterpret_cast<PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT>(Context),
&ConvertedOutput);
}

EXTERN_C HRESULT WINAPI NanaZipCodecsLz4Decode(
_In_ PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT StreamContext,
_In_ UINT32 NumberOfThreads,
_In_ UINT32 InputSize)
{
LZ4MT_RdWr_t ReadWrite = { 0 };
ReadWrite.fn_read = ::NanaZipCodecsLz4Read;
ReadWrite.fn_write = ::NanaZipCodecsLz4Write;
ReadWrite.arg_read = reinterpret_cast<void*>(&StreamContext);
ReadWrite.arg_write = reinterpret_cast<void*>(&StreamContext);

LZ4MT_DCtx* Context = ::LZ4MT_createDCtx(NumberOfThreads, InputSize);
if (!Context)
{
return S_FALSE;
}

std::size_t Result = ::LZ4MT_decompressDCtx(Context, &ReadWrite);
if (::LZ4MT_isError(Result))
{
if (ERROR(canceled) == Result)
{
return E_ABORT;
}

return E_FAIL;
}

::LZ4MT_freeDCtx(Context);

return S_OK;
}
5 changes: 5 additions & 0 deletions NanaZip.Codecs/NanaZip.Codecs.MultiThreadWrapper.LZ4.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ EXTERN_C int NanaZipCodecsLz4Write(
void* Context,
LZ4MT_Buffer* Output);

EXTERN_C HRESULT WINAPI NanaZipCodecsLz4Decode(
_In_ PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT StreamContext,
_In_ UINT32 NumberOfThreads,
_In_ UINT32 InputSize);

#endif // !NANAZIP_CODECS_MULTI_THREAD_WRAPPER_LZ4
35 changes: 35 additions & 0 deletions NanaZip.Codecs/NanaZip.Codecs.MultiThreadWrapper.LZ5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "NanaZip.Codecs.MultiThreadWrapper.LZ5.h"

#include <cstddef>

EXTERN_C int NanaZipCodecsLz5Read(
void* Context,
LZ5MT_Buffer* Input)
Expand All @@ -35,3 +37,36 @@ EXTERN_C int NanaZipCodecsLz5Write(
reinterpret_cast<PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT>(Context),
&ConvertedOutput);
}

EXTERN_C HRESULT WINAPI NanaZipCodecsLz5Decode(
_In_ PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT StreamContext,
_In_ UINT32 NumberOfThreads,
_In_ UINT32 InputSize)
{
LZ5MT_RdWr_t ReadWrite = { 0 };
ReadWrite.fn_read = ::NanaZipCodecsLz5Read;
ReadWrite.fn_write = ::NanaZipCodecsLz5Write;
ReadWrite.arg_read = reinterpret_cast<void*>(&StreamContext);
ReadWrite.arg_write = reinterpret_cast<void*>(&StreamContext);

LZ5MT_DCtx* Context = ::LZ5MT_createDCtx(NumberOfThreads, InputSize);
if (!Context)
{
return S_FALSE;
}

std::size_t Result = ::LZ5MT_decompressDCtx(Context, &ReadWrite);
if (::LZ5MT_isError(Result))
{
if (ERROR(canceled) == Result)
{
return E_ABORT;
}

return E_FAIL;
}

::LZ5MT_freeDCtx(Context);

return S_OK;
}
5 changes: 5 additions & 0 deletions NanaZip.Codecs/NanaZip.Codecs.MultiThreadWrapper.LZ5.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ EXTERN_C int NanaZipCodecsLz5Write(
void* Context,
LZ5MT_Buffer* Output);

EXTERN_C HRESULT WINAPI NanaZipCodecsLz5Decode(
_In_ PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT StreamContext,
_In_ UINT32 NumberOfThreads,
_In_ UINT32 InputSize);

#endif // !NANAZIP_CODECS_MULTI_THREAD_WRAPPER_LZ5
35 changes: 35 additions & 0 deletions NanaZip.Codecs/NanaZip.Codecs.MultiThreadWrapper.Lizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "NanaZip.Codecs.MultiThreadWrapper.Lizard.h"

#include <cstddef>

EXTERN_C int NanaZipCodecsLizardRead(
void* Context,
LIZARDMT_Buffer* Input)
Expand All @@ -35,3 +37,36 @@ EXTERN_C int NanaZipCodecsLizardWrite(
reinterpret_cast<PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT>(Context),
&ConvertedOutput);
}

EXTERN_C HRESULT WINAPI NanaZipCodecsLizardDecode(
_In_ PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT StreamContext,
_In_ UINT32 NumberOfThreads,
_In_ UINT32 InputSize)
{
LIZARDMT_RdWr_t ReadWrite = { 0 };
ReadWrite.fn_read = ::NanaZipCodecsLizardRead;
ReadWrite.fn_write = ::NanaZipCodecsLizardWrite;
ReadWrite.arg_read = reinterpret_cast<void*>(&StreamContext);
ReadWrite.arg_write = reinterpret_cast<void*>(&StreamContext);

LIZARDMT_DCtx* Context = ::LIZARDMT_createDCtx(NumberOfThreads, InputSize);
if (!Context)
{
return S_FALSE;
}

std::size_t Result = ::LIZARDMT_decompressDCtx(Context, &ReadWrite);
if (::LIZARDMT_isError(Result))
{
if (ERROR(canceled) == Result)
{
return E_ABORT;
}

return E_FAIL;
}

::LIZARDMT_freeDCtx(Context);

return S_OK;
}
5 changes: 5 additions & 0 deletions NanaZip.Codecs/NanaZip.Codecs.MultiThreadWrapper.Lizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ EXTERN_C int NanaZipCodecsLizardWrite(
void* Context,
LIZARDMT_Buffer* Output);

EXTERN_C HRESULT WINAPI NanaZipCodecsLizardDecode(
_In_ PNANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT StreamContext,
_In_ UINT32 NumberOfThreads,
_In_ UINT32 InputSize);

#endif // !NANAZIP_CODECS_MULTI_THREAD_WRAPPER_LIZARD
12 changes: 3 additions & 9 deletions NanaZip.Codecs/NanaZip.Codecs.def
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ NanaZipCodecsLz5Read
NanaZipCodecsLz5Write

NanaZipCodecsBrotliDecode
NanaZipCodecsLizardDecode
NanaZipCodecsLz4Decode
NanaZipCodecsLz5Decode

LZ4_decompress_safe

Expand All @@ -23,24 +26,15 @@ BROTLIMT_freeCCtx
BROTLIMT_isError
LIZARDMT_compressCCtx
LIZARDMT_createCCtx
LIZARDMT_createDCtx
LIZARDMT_decompressDCtx
LIZARDMT_freeCCtx
LIZARDMT_freeDCtx
LIZARDMT_isError
LZ4MT_compressCCtx
LZ4MT_createCCtx
LZ4MT_createDCtx
LZ4MT_decompressDCtx
LZ4MT_freeCCtx
LZ4MT_freeDCtx
LZ4MT_isError
LZ5MT_compressCCtx
LZ5MT_createCCtx
LZ5MT_createDCtx
LZ5MT_decompressDCtx
LZ5MT_freeCCtx
LZ5MT_freeDCtx
LZ5MT_isError

FL2_cancelCStream
Expand Down
28 changes: 1 addition & 27 deletions NanaZip.Core/Extensions/ZSCodecs/LizardDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,13 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 * outSize)
HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
ISequentialOutStream * outStream, ICompressProgressInfo * progress)
{
LIZARDMT_RdWr_t rdwr;
size_t result;
HRESULT res = S_OK;

NANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT Context = { 0 };
Context.InputStream = inStream;
Context.OutputStream = outStream;
Context.Progress = progress;
Context.ProcessedInputSize = &_processedIn;
Context.ProcessedOutputSize = &_processedOut;

/* 1) setup read/write functions */
rdwr.fn_read = ::NanaZipCodecsLizardRead;
rdwr.fn_write = ::NanaZipCodecsLizardWrite;
rdwr.arg_read = reinterpret_cast<void*>(&Context);
rdwr.arg_write = reinterpret_cast<void*>(&Context);

/* 2) create decompression context */
LIZARDMT_DCtx *ctx = LIZARDMT_createDCtx(_numThreads, _inputSize);
if (!ctx)
return S_FALSE;

/* 3) decompress */
result = LIZARDMT_decompressDCtx(ctx, &rdwr);
if (LIZARDMT_isError(result)) {
if (result == (size_t)-LIZARDMT_error_canceled)
return E_ABORT;
return E_FAIL;
}

/* 4) free resources */
LIZARDMT_freeDCtx(ctx);
return res;
return ::NanaZipCodecsLizardDecode(&Context, _numThreads, _inputSize);
}

STDMETHODIMP CDecoder::Code(ISequentialInStream * inStream, ISequentialOutStream * outStream,
Expand Down
28 changes: 1 addition & 27 deletions NanaZip.Core/Extensions/ZSCodecs/Lz4Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,13 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 * outSize)
HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
ISequentialOutStream * outStream, ICompressProgressInfo * progress)
{
LZ4MT_RdWr_t rdwr;
size_t result;
HRESULT res = S_OK;

NANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT Context = { 0 };
Context.InputStream = inStream;
Context.OutputStream = outStream;
Context.Progress = progress;
Context.ProcessedInputSize = &_processedIn;
Context.ProcessedOutputSize = &_processedOut;

/* 1) setup read/write functions */
rdwr.fn_read = ::NanaZipCodecsLz4Read;
rdwr.fn_write = ::NanaZipCodecsLz4Write;
rdwr.arg_read = reinterpret_cast<void*>(&Context);
rdwr.arg_write = reinterpret_cast<void*>(&Context);

/* 2) create decompression context */
LZ4MT_DCtx *ctx = LZ4MT_createDCtx(_numThreads, _inputSize);
if (!ctx)
return S_FALSE;

/* 3) decompress */
result = LZ4MT_decompressDCtx(ctx, &rdwr);
if (LZ4MT_isError(result)) {
if (result == (size_t)-LZ4MT_error_canceled)
return E_ABORT;
return E_FAIL;
}

/* 4) free resources */
LZ4MT_freeDCtx(ctx);
return res;
return ::NanaZipCodecsLz4Decode(&Context, _numThreads, _inputSize);
}

STDMETHODIMP CDecoder::Code(ISequentialInStream * inStream, ISequentialOutStream * outStream,
Expand Down
28 changes: 1 addition & 27 deletions NanaZip.Core/Extensions/ZSCodecs/Lz5Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,13 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 * outSize)
HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
ISequentialOutStream * outStream, ICompressProgressInfo * progress)
{
LZ5MT_RdWr_t rdwr;
size_t result;
HRESULT res = S_OK;

NANAZIP_CODECS_ZSTDMT_STREAM_CONTEXT Context = { 0 };
Context.InputStream = inStream;
Context.OutputStream = outStream;
Context.Progress = progress;
Context.ProcessedInputSize = &_processedIn;
Context.ProcessedOutputSize = &_processedOut;

/* 1) setup read/write functions */
rdwr.fn_read = ::NanaZipCodecsLz5Read;
rdwr.fn_write = ::NanaZipCodecsLz5Write;
rdwr.arg_read = reinterpret_cast<void*>(&Context);
rdwr.arg_write = reinterpret_cast<void*>(&Context);

/* 2) create decompression context */
LZ5MT_DCtx *ctx = LZ5MT_createDCtx(_numThreads, _inputSize);
if (!ctx)
return S_FALSE;

/* 3) decompress */
result = LZ5MT_decompressDCtx(ctx, &rdwr);
if (LZ5MT_isError(result)) {
if (result == (size_t)-LZ5MT_error_canceled)
return E_ABORT;
return E_FAIL;
}

/* 4) free resources */
LZ5MT_freeDCtx(ctx);
return res;
return ::NanaZipCodecsLz5Decode(&Context, _numThreads, _inputSize);
}

STDMETHODIMP CDecoder::Code(ISequentialInStream * inStream, ISequentialOutStream * outStream,
Expand Down

0 comments on commit 8c42b78

Please sign in to comment.