mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 11:14:58 -06:00
- Minor speed optimization for LZMA2 (xz and 7z) multi-threading compression.
7-Zip now uses additional memory buffers for multi-block LZMA2 compression.
CPU utilization was slightly improved.
- 7-zip now creates multi-block xz archives by default. Block size can be
specified with -ms[Size]{m|g} switch.
- xz decoder now can unpack random block from multi-block xz archives. 7-Zip
File Manager now can open nested multi-block xz archives (for example,
image.iso.xz) without full unpacking of xz archive.
- 7-Zip now can create zip archives from stdin to stdout.
- 7-Zip command line: @listfile now doesn't work after -- switch. Use
-i@listfile before -- switch instead.
fixed bugs:
- 7-Zip could add unrequired alternate file streams to WIM archives, for
commands that contain filename wildcards and -sns switch.
- 7-Zip 17.00 beta crashed for commands that write anti-item to 7z archive.
- 7-Zip 17.00 beta ignored "Use large memory pages" option.
123 lines
3.0 KiB
C++
123 lines
3.0 KiB
C++
// Lzma2Encoder.cpp
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "../../../C/Alloc.h"
|
|
|
|
#include "../Common/CWrappers.h"
|
|
#include "../Common/StreamUtils.h"
|
|
|
|
#include "Lzma2Encoder.h"
|
|
|
|
namespace NCompress {
|
|
|
|
namespace NLzma {
|
|
|
|
HRESULT SetLzmaProp(PROPID propID, const PROPVARIANT &prop, CLzmaEncProps &ep);
|
|
|
|
}
|
|
|
|
namespace NLzma2 {
|
|
|
|
CEncoder::CEncoder()
|
|
{
|
|
_encoder = NULL;
|
|
_encoder = Lzma2Enc_Create(&g_Alloc, &g_BigAlloc);
|
|
if (!_encoder)
|
|
throw 1;
|
|
}
|
|
|
|
CEncoder::~CEncoder()
|
|
{
|
|
if (_encoder)
|
|
Lzma2Enc_Destroy(_encoder);
|
|
}
|
|
|
|
|
|
HRESULT SetLzma2Prop(PROPID propID, const PROPVARIANT &prop, CLzma2EncProps &lzma2Props)
|
|
{
|
|
switch (propID)
|
|
{
|
|
case NCoderPropID::kBlockSize:
|
|
{
|
|
if (prop.vt == VT_UI4)
|
|
lzma2Props.blockSize = prop.ulVal;
|
|
else if (prop.vt == VT_UI8)
|
|
lzma2Props.blockSize = prop.uhVal.QuadPart;
|
|
else
|
|
return E_INVALIDARG;
|
|
break;
|
|
}
|
|
case NCoderPropID::kNumThreads:
|
|
if (prop.vt != VT_UI4) return E_INVALIDARG; lzma2Props.numTotalThreads = (int)(prop.ulVal); break;
|
|
default:
|
|
RINOK(NLzma::SetLzmaProp(propID, prop, lzma2Props.lzmaProps));
|
|
}
|
|
return S_OK;
|
|
}
|
|
|
|
|
|
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
|
const PROPVARIANT *coderProps, UInt32 numProps)
|
|
{
|
|
CLzma2EncProps lzma2Props;
|
|
Lzma2EncProps_Init(&lzma2Props);
|
|
|
|
for (UInt32 i = 0; i < numProps; i++)
|
|
{
|
|
RINOK(SetLzma2Prop(propIDs[i], coderProps[i], lzma2Props));
|
|
}
|
|
return SResToHRESULT(Lzma2Enc_SetProps(_encoder, &lzma2Props));
|
|
}
|
|
|
|
|
|
STDMETHODIMP CEncoder::SetCoderPropertiesOpt(const PROPID *propIDs,
|
|
const PROPVARIANT *coderProps, UInt32 numProps)
|
|
{
|
|
for (UInt32 i = 0; i < numProps; i++)
|
|
{
|
|
const PROPVARIANT &prop = coderProps[i];
|
|
PROPID propID = propIDs[i];
|
|
if (propID == NCoderPropID::kExpectedDataSize)
|
|
if (prop.vt == VT_UI8)
|
|
Lzma2Enc_SetDataSize(_encoder, prop.uhVal.QuadPart);
|
|
}
|
|
return S_OK;
|
|
}
|
|
|
|
|
|
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
|
|
{
|
|
Byte prop = Lzma2Enc_WriteProperties(_encoder);
|
|
return WriteStream(outStream, &prop, 1);
|
|
}
|
|
|
|
|
|
#define RET_IF_WRAP_ERROR(wrapRes, sRes, sResErrorCode) \
|
|
if (wrapRes != S_OK /* && (sRes == SZ_OK || sRes == sResErrorCode) */) return wrapRes;
|
|
|
|
STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
|
const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
|
|
{
|
|
CSeqInStreamWrap inWrap;
|
|
CSeqOutStreamWrap outWrap;
|
|
CCompressProgressWrap progressWrap;
|
|
|
|
inWrap.Init(inStream);
|
|
outWrap.Init(outStream);
|
|
progressWrap.Init(progress);
|
|
|
|
SRes res = Lzma2Enc_Encode2(_encoder,
|
|
&outWrap.vt, NULL, NULL,
|
|
&inWrap.vt, NULL, 0,
|
|
progress ? &progressWrap.vt : NULL);
|
|
|
|
RET_IF_WRAP_ERROR(inWrap.Res, res, SZ_ERROR_READ)
|
|
RET_IF_WRAP_ERROR(outWrap.Res, res, SZ_ERROR_WRITE)
|
|
RET_IF_WRAP_ERROR(progressWrap.Res, res, SZ_ERROR_PROGRESS)
|
|
|
|
return SResToHRESULT(res);
|
|
}
|
|
|
|
}}
|