コード例 #1
0
ファイル: Lzma2Enc.cs プロジェクト: yamiM0NSTER/managed-lzma
            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
            }
コード例 #2
0
ファイル: Lzma2Enc.cs プロジェクト: yamiM0NSTER/managed-lzma
            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);
            }
コード例 #3
0
ファイル: LzmaEnc.cs プロジェクト: modulexcite/managed-lzma
 internal void RangeEnc_Construct()
 {
     mOutStream = null;
     mBufBase = null;
 }
コード例 #4
0
ファイル: LzmaEnc.cs プロジェクト: modulexcite/managed-lzma
 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);
 }
コード例 #5
0
ファイル: LzmaEnc.cs プロジェクト: modulexcite/managed-lzma
            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);
            }
コード例 #6
0
ファイル: Lzma2Enc.cs プロジェクト: yamiM0NSTER/managed-lzma
            internal SRes Lzma2EncInt_EncodeSubblock(P <byte> outBuf, ref long packSizeRes, ISeqOutStream outStream)
            {
                long packSizeLimit = packSizeRes;
                long packSize      = packSizeLimit;
                uint unpackSize    = LZMA2_UNPACK_SIZE_MAX;
                uint lzHeaderSize  = 5u + (mNeedInitProp ? 1u : 0u);

                packSizeRes = 0;
                if (packSize < lzHeaderSize)
                {
                    return(SZ_ERROR_OUTPUT_EOF);
                }
                packSize -= lzHeaderSize;

                mEnc.LzmaEnc_SaveState();
                SRes res = mEnc.LzmaEnc_CodeOneMemBlock(mNeedInitState, outBuf + lzHeaderSize, ref packSize, LZMA2_PACK_SIZE_MAX, ref unpackSize);

                TR("Lzma2EncInt_EncodeSubblock:packSize", checked ((int)packSize));
                TR("Lzma2EncInt_EncodeSubblock:unpackSize", unpackSize);
                DebugPrint("\npackSize = {0:0000000} unpackSize = {1:0000000}  ", packSize, unpackSize);

                if (unpackSize == 0)
                {
                    return(res);
                }

                bool useCopyBlock;

                if (res == SZ_OK)
                {
                    useCopyBlock = (packSize + 2 >= unpackSize || packSize > (1 << 16));
                }
                else
                {
                    if (res != SZ_ERROR_OUTPUT_EOF)
                    {
                        return(res);
                    }
                    res          = SZ_OK;
                    useCopyBlock = true;
                }

                if (useCopyBlock)
                {
                    long destPos = 0;
                    DebugPrint("################# COPY           ");

                    while (unpackSize > 0)
                    {
                        uint u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;
                        if (packSizeLimit - destPos < u + 3)
                        {
                            return(SZ_ERROR_OUTPUT_EOF);
                        }

                        outBuf[destPos++] = (byte)(mSrcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET);
                        outBuf[destPos++] = (byte)((u - 1) >> 8);
                        outBuf[destPos++] = (byte)(u - 1);

                        CUtils.memcpy(outBuf + destPos, mEnc.LzmaEnc_GetCurBuf() - unpackSize, u);

                        unpackSize -= u;
                        destPos    += u;
                        mSrcPos    += u;

                        if (outStream != null)
                        {
                            packSizeRes += destPos;
                            if (outStream.Write(outBuf, destPos) != destPos)
                            {
                                return(SZ_ERROR_WRITE);
                            }
                            destPos = 0;
                        }
                        else
                        {
                            packSizeRes = destPos;
                        }

                        /* needInitState = true; */
                    }

                    mEnc.LzmaEnc_RestoreState();
                    return(SZ_OK);
                }
                else
                {
                    long destPos = 0;
                    uint u       = unpackSize - 1;
                    uint pm      = (uint)(packSize - 1);

                    uint mode;
                    if (mSrcPos == 0)
                    {
                        mode = 3;
                    }
                    else if (!mNeedInitState)
                    {
                        mode = 0;
                    }
                    else if (!mNeedInitProp)
                    {
                        mode = 1;
                    }
                    else
                    {
                        mode = 2;
                    }

                    DebugPrint("               ");

                    outBuf[destPos++] = (byte)(LZMA2_CONTROL_LZMA | (mode << 5) | ((u >> 16) & 0x1F));
                    outBuf[destPos++] = (byte)(u >> 8);
                    outBuf[destPos++] = (byte)u;
                    outBuf[destPos++] = (byte)(pm >> 8);
                    outBuf[destPos++] = (byte)pm;

                    if (mNeedInitProp)
                    {
                        outBuf[destPos++] = mProps;
                    }

                    mNeedInitProp  = false;
                    mNeedInitState = false;
                    destPos       += packSize;
                    mSrcPos       += unpackSize;

                    if (outStream != null && outStream.Write(outBuf, destPos) != destPos)
                    {
                        return(SZ_ERROR_WRITE);
                    }

                    packSizeRes = destPos;
                    return(SZ_OK);
                }
            }
コード例 #7
0
ファイル: Lzma2Enc.cs プロジェクト: modulexcite/managed-lzma
            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
            }
コード例 #8
0
ファイル: Lzma2Enc.cs プロジェクト: modulexcite/managed-lzma
            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;
            }
コード例 #9
0
ファイル: Lzma2Enc.cs プロジェクト: modulexcite/managed-lzma
            internal SRes Lzma2EncInt_EncodeSubblock(P<byte> outBuf, ref long packSizeRes, ISeqOutStream outStream)
            {
                long packSizeLimit = packSizeRes;
                long packSize = packSizeLimit;
                uint unpackSize = LZMA2_UNPACK_SIZE_MAX;
                uint lzHeaderSize = 5u + (mNeedInitProp ? 1u : 0u);

                packSizeRes = 0;
                if (packSize < lzHeaderSize)
                    return SZ_ERROR_OUTPUT_EOF;
                packSize -= lzHeaderSize;

                mEnc.LzmaEnc_SaveState();
                SRes res = mEnc.LzmaEnc_CodeOneMemBlock(mNeedInitState, outBuf + lzHeaderSize, ref packSize, LZMA2_PACK_SIZE_MAX, ref unpackSize);

                TR("Lzma2EncInt_EncodeSubblock:packSize", checked((int)packSize));
                TR("Lzma2EncInt_EncodeSubblock:unpackSize", unpackSize);
                DebugPrint("\npackSize = {0:0000000} unpackSize = {1:0000000}  ", packSize, unpackSize);

                if (unpackSize == 0)
                    return res;

                bool useCopyBlock;
                if (res == SZ_OK)
                    useCopyBlock = (packSize + 2 >= unpackSize || packSize > (1 << 16));
                else
                {
                    if (res != SZ_ERROR_OUTPUT_EOF)
                        return res;
                    res = SZ_OK;
                    useCopyBlock = true;
                }

                if (useCopyBlock)
                {
                    long destPos = 0;
                    DebugPrint("################# COPY           ");

                    while (unpackSize > 0)
                    {
                        uint u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;
                        if (packSizeLimit - destPos < u + 3)
                            return SZ_ERROR_OUTPUT_EOF;

                        outBuf[destPos++] = (byte)(mSrcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET);
                        outBuf[destPos++] = (byte)((u - 1) >> 8);
                        outBuf[destPos++] = (byte)(u - 1);

                        CUtils.memcpy(outBuf + destPos, mEnc.LzmaEnc_GetCurBuf() - unpackSize, u);

                        unpackSize -= u;
                        destPos += u;
                        mSrcPos += u;

                        if (outStream != null)
                        {
                            packSizeRes += destPos;
                            if (outStream.Write(outBuf, destPos) != destPos)
                                return SZ_ERROR_WRITE;
                            destPos = 0;
                        }
                        else
                        {
                            packSizeRes = destPos;
                        }

                        /* needInitState = true; */
                    }

                    mEnc.LzmaEnc_RestoreState();
                    return SZ_OK;
                }
                else
                {
                    long destPos = 0;
                    uint u = unpackSize - 1;
                    uint pm = (uint)(packSize - 1);

                    uint mode;
                    if (mSrcPos == 0)
                        mode = 3;
                    else if (!mNeedInitState)
                        mode = 0;
                    else if (!mNeedInitProp)
                        mode = 1;
                    else
                        mode = 2;

                    DebugPrint("               ");

                    outBuf[destPos++] = (byte)(LZMA2_CONTROL_LZMA | (mode << 5) | ((u >> 16) & 0x1F));
                    outBuf[destPos++] = (byte)(u >> 8);
                    outBuf[destPos++] = (byte)u;
                    outBuf[destPos++] = (byte)(pm >> 8);
                    outBuf[destPos++] = (byte)pm;

                    if (mNeedInitProp)
                        outBuf[destPos++] = mProps;

                    mNeedInitProp = false;
                    mNeedInitState = false;
                    destPos += packSize;
                    mSrcPos += unpackSize;

                    if (outStream != null && outStream.Write(outBuf, destPos) != destPos)
                        return SZ_ERROR_WRITE;

                    packSizeRes = destPos;
                    return SZ_OK;
                }
            }