internal void MtProgress_Init(ICompressProgress progress) { for (uint i = 0; i < NUM_MT_CODER_THREADS_MAX; i++) { mInSizes[i] = mOutSizes[i] = 0; } mTotalInSize = 0; mTotalOutSize = 0; mProgress = progress; mRes = SZ_OK; }
/* ---------- One Call Interface ---------- */ /* LzmaEncode Return code: SZ_OK - OK SZ_ERROR_MEM - Memory allocation error SZ_ERROR_PARAM - Incorrect paramater SZ_ERROR_OUTPUT_EOF - output buffer overflow SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) */ public static SRes LzmaEncode(P<byte> dest, ref long destLen, P<byte> src, long srcLen, CLzmaEncProps props, P<byte> propsEncoded, ref long propsSize, bool writeEndMark, ICompressProgress progress, ISzAlloc alloc, ISzAlloc allocBig) { CLzmaEnc encoder = LzmaEnc_Create(alloc); if (encoder == null) return SZ_ERROR_MEM; SRes res; res = encoder.LzmaEnc_SetProps(props); if (res == SZ_OK) { res = encoder.LzmaEnc_WriteProperties(propsEncoded, ref propsSize); if (res == SZ_OK) res = encoder.LzmaEnc_MemEncode(dest, ref destLen, src, srcLen, writeEndMark, progress, alloc, allocBig); } encoder.LzmaEnc_Destroy(alloc, allocBig); return res; }
private SRes LzmaEnc_Encode2(ICompressProgress progress) { SRes res = SZ_OK; for (;;) { res = LzmaEnc_CodeOneBlock(false, 0, 0); if (res != SZ_OK || mFinished) break; if (progress != null) { res = progress.Progress(mNowPos64, mRC.RangeEnc_GetProcessed()); if (res != SZ_OK) { res = SZ_ERROR_PROGRESS; break; } } } LzmaEnc_Finish(); return res; }
public SRes LzmaEnc_MemEncode(P<byte> dest, ref long destLen, P<byte> src, long srcLen, bool writeEndMark, ICompressProgress progress, ISzAlloc alloc, ISzAlloc allocBig) { CSeqOutStreamBuf outStream = new CSeqOutStreamBuf(); LzmaEnc_SetInputBuf(src, srcLen); outStream.mData = dest; outStream.mRem = destLen; outStream.mOverflow = false; mWriteEndMark = writeEndMark; mRC.mOutStream = outStream; SRes res = LzmaEnc_MemPrepare(src, srcLen, 0, alloc, allocBig); if (res == SZ_OK) res = LzmaEnc_Encode2(progress); destLen -= outStream.mRem; if (outStream.mOverflow) return SZ_ERROR_OUTPUT_EOF; return res; }
public SRes LzmaEnc_Encode(ISeqOutStream outStream, ISeqInStream inStream, ICompressProgress progress, ISzAlloc alloc, ISzAlloc allocBig) { SRes res; if ((res = LzmaEnc_Prepare(outStream, inStream, alloc, allocBig)) != SZ_OK) return res; return LzmaEnc_Encode2(progress); }
public SRes Lzma2Enc_Encode(ISeqOutStream outStream, ISeqInStream inStream, ICompressProgress progress) { for (int i = 0; i < mProps.mNumBlockThreads; i++) { CLzma2EncInternal t = mCoders[i]; if (t.mEnc == null) { t.mEnc = LzmaEnc_Create(mAlloc); if (t.mEnc == null) { return(SZ_ERROR_MEM); } } } #if !_7ZIP_ST if (mProps.mNumBlockThreads <= 1) #endif return(mCoders[0].Lzma2Enc_EncodeMt1(this, outStream, inStream, progress)); #if !_7ZIP_ST mMtCoder.mProgress = progress; mMtCoder.mInStream = inStream; mMtCoder.mOutStream = outStream; mMtCoder.mAlloc = mAlloc; mMtCoder.mMtCallback = new CMtCallbackImp(this); mMtCoder.mBlockSize = mProps.mBlockSize; mMtCoder.mDestBlockSize = mProps.mBlockSize + (mProps.mBlockSize >> 10) + 16; mMtCoder.mNumThreads = mProps.mNumBlockThreads; return(mMtCoder.MtCoder_Code()); #endif }
internal SRes Lzma2Enc_EncodeMt1(CLzma2Enc mainEncoder, ISeqOutStream outStream, ISeqInStream inStream, ICompressProgress progress) { ulong packTotal = 0; SRes res = SZ_OK; if (mainEncoder.mOutBuf == null) { mainEncoder.mOutBuf = IAlloc_AllocBytes(mainEncoder.mAlloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX); if (mainEncoder.mOutBuf == null) { return(SZ_ERROR_MEM); } } if ((res = Lzma2EncInt_Init(mainEncoder.mProps)) != SZ_OK) { return(res); } if ((res = mEnc.LzmaEnc_PrepareForLzma2(inStream, LZMA2_KEEP_WINDOW_SIZE, mainEncoder.mAlloc, mainEncoder.mAllocBig)) != SZ_OK) { return(res); } for (;;) { long packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX; res = Lzma2EncInt_EncodeSubblock(mainEncoder.mOutBuf, ref packSize, outStream); if (res != SZ_OK) { break; } packTotal += (ulong)packSize; res = Progress(progress, mSrcPos, packTotal); if (res != SZ_OK) { break; } if (packSize == 0) { break; } } mEnc.LzmaEnc_Finish(); if (res == SZ_OK) { if (outStream.Write(new byte[] { 0 }, 1) != 1) { return(SZ_ERROR_WRITE); } } return(res); }
private static SRes Progress(ICompressProgress p, ulong inSize, ulong outSize) { return((p != null && p.Progress(inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK); }
private static SRes Progress(ICompressProgress p, ulong inSize, ulong outSize) { return (p != null && p.Progress(inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; }
internal void MtProgress_Init(ICompressProgress progress) { for(uint i = 0; i < NUM_MT_CODER_THREADS_MAX; i++) mInSizes[i] = mOutSizes[i] = 0; mTotalInSize = 0; mTotalOutSize = 0; mProgress = progress; mRes = SZ_OK; }
public SRes Lzma2Enc_Encode(ISeqOutStream outStream, ISeqInStream inStream, ICompressProgress progress) { for (int i = 0; i < mProps.mNumBlockThreads; i++) { CLzma2EncInternal t = mCoders[i]; if (t.mEnc == null) { t.mEnc = LzmaEnc_Create(mAlloc); if (t.mEnc == null) return SZ_ERROR_MEM; } } #if !_7ZIP_ST if (mProps.mNumBlockThreads <= 1) #endif return mCoders[0].Lzma2Enc_EncodeMt1(this, outStream, inStream, progress); #if !_7ZIP_ST mMtCoder.mProgress = progress; mMtCoder.mInStream = inStream; mMtCoder.mOutStream = outStream; mMtCoder.mAlloc = mAlloc; mMtCoder.mMtCallback = new CMtCallbackImp(this); mMtCoder.mBlockSize = mProps.mBlockSize; mMtCoder.mDestBlockSize = mProps.mBlockSize + (mProps.mBlockSize >> 10) + 16; mMtCoder.mNumThreads = mProps.mNumBlockThreads; return mMtCoder.MtCoder_Code(); #endif }
internal SRes Lzma2Enc_EncodeMt1(CLzma2Enc mainEncoder, ISeqOutStream outStream, ISeqInStream inStream, ICompressProgress progress) { ulong packTotal = 0; SRes res = SZ_OK; if (mainEncoder.mOutBuf == null) { mainEncoder.mOutBuf = IAlloc_AllocBytes(mainEncoder.mAlloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX); if (mainEncoder.mOutBuf == null) return SZ_ERROR_MEM; } if ((res = Lzma2EncInt_Init(mainEncoder.mProps)) != SZ_OK) return res; if ((res = mEnc.LzmaEnc_PrepareForLzma2(inStream, LZMA2_KEEP_WINDOW_SIZE, mainEncoder.mAlloc, mainEncoder.mAllocBig)) != SZ_OK) return res; for (;;) { long packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX; res = Lzma2EncInt_EncodeSubblock(mainEncoder.mOutBuf, ref packSize, outStream); if (res != SZ_OK) break; packTotal += (ulong)packSize; res = Progress(progress, mSrcPos, packTotal); if (res != SZ_OK) break; if (packSize == 0) break; } mEnc.LzmaEnc_Finish(); if (res == SZ_OK) { if (outStream.Write(new byte[] { 0 }, 1) != 1) return SZ_ERROR_WRITE; } return res; }