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 static SRes FullRead(ISeqInStream stream, P <byte> data, ref long processedSize) { long size = processedSize; processedSize = 0; while (size != 0) { long curSize = size; SRes res = stream.Read(data, ref curSize); processedSize += curSize; data += curSize; size -= curSize; if (res != SZ_OK) { return(res); } if (curSize == 0) { return(SZ_OK); } } return(SZ_OK); }
internal SRes LzmaEnc_PrepareForLzma2(ISeqInStream inStream, uint keepWindowSize, ISzAlloc alloc, ISzAlloc allocBig) { mMatchFinderBase.mStream = inStream; mNeedInit = true; return LzmaEnc_AllocAndInit(keepWindowSize, alloc, allocBig); }
internal SRes LzmaEnc_Prepare(ISeqOutStream outStream, ISeqInStream inStream, ISzAlloc alloc, ISzAlloc allocBig) { mMatchFinderBase.mStream = inStream; mNeedInit = true; mRC.mOutStream = outStream; return LzmaEnc_AllocAndInit(0, alloc, allocBig); }
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); }
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); }
internal static SRes FullRead(ISeqInStream stream, P<byte> data, ref long processedSize) { long size = processedSize; processedSize = 0; while(size != 0) { long curSize = size; SRes res = stream.Read(data, ref curSize); processedSize += curSize; data += curSize; size -= curSize; if(res != SZ_OK) return res; if(curSize == 0) return SZ_OK; } return 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; }