예제 #1
0
파일: LzmaLib.cs 프로젝트: 0-v-0/tiny7z
        /*
         * LzmaUncompress
         * --------------
         * In:
         * dest     - output data
         * destLen  - output data size
         * src      - input data
         * srcLen   - input data size
         * Out:
         * destLen  - processed output size
         * srcLen   - processed input size
         * Returns:
         * SZ_OK                - OK
         * SZ_ERROR_DATA        - Data error
         * SZ_ERROR_MEM         - Memory allocation arror
         * SZ_ERROR_UNSUPPORTED - Unsupported properties
         * SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)
         */

        public static SRes LzmaUncompress(
            P <byte> dest, ref long destLen,
            P <byte> src, ref long srcLen,
            P <byte> props, long propsSize)
        {
            ELzmaStatus status;

            return(CLzmaDec.LzmaDecode(dest, ref destLen, src, ref srcLen, props, (uint)propsSize, ELzmaFinishMode.LZMA_FINISH_ANY, out status, ISzAlloc.SmallAlloc));
        }
예제 #2
0
 private static void LzmaDec_UpdateWithUncompressed(CLzmaDec p, P <byte> src, long size)
 {
     CUtils.memcpy(p.mDic + p.mDicPos, src, size);
     p.mDicPos += size;
     if (p.mCheckDicSize == 0 && p.mProp.mDicSize - p.mProcessedPos <= size)
     {
         p.mCheckDicSize = p.mProp.mDicSize;
     }
     p.mProcessedPos += (uint)size;
 }
예제 #3
0
 private static void LzmaDec_UpdateWithUncompressed(CLzmaDec p, P<byte> src, long size)
 {
     CUtils.memcpy(p.mDic + p.mDicPos, src, size);
     p.mDicPos += size;
     if (p.mCheckDicSize == 0 && p.mProp.mDicSize - p.mProcessedPos <= size)
         p.mCheckDicSize = p.mProp.mDicSize;
     p.mProcessedPos += (uint)size;
 }
예제 #4
0
            /* ---------- One Call Interface ---------- */

            /* LzmaDecode

            finishMode:
              It has meaning only if the decoding reaches output limit (*destLen).
              LZMA_FINISH_ANY - Decode just destLen bytes.
              LZMA_FINISH_END - Stream must be finished after (*destLen).

            Returns:
              SZ_OK
                status:
                  LZMA_STATUS_FINISHED_WITH_MARK
                  LZMA_STATUS_NOT_FINISHED
                  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
              SZ_ERROR_DATA - Data error
              SZ_ERROR_MEM  - Memory allocation error
              SZ_ERROR_UNSUPPORTED - Unsupported properties
              SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
            */

            public static SRes LzmaDecode(P<byte> dest, ref long destLen, P<byte> src, ref long srcLen, P<byte> propData, uint propSize, ELzmaFinishMode finishMode, out ELzmaStatus status, ISzAlloc alloc)
            {
                long outSize = destLen;
                long inSize = srcLen;
                destLen = 0;
                srcLen = 0;
                status = ELzmaStatus.LZMA_STATUS_NOT_SPECIFIED;

                if (inSize < RC_INIT_SIZE)
                    return SZ_ERROR_INPUT_EOF;

                CLzmaDec decoder = new CLzmaDec();
                decoder.LzmaDec_Construct();

                SRes res;
                if ((res = decoder.LzmaDec_AllocateProbs(propData, propSize, alloc)) != SZ_OK)
                    return res;

                decoder.mDic = dest;
                decoder.mDicBufSize = outSize;
                decoder.LzmaDec_Init();
                srcLen = inSize;

                res = decoder.LzmaDec_DecodeToDic(outSize, src, ref srcLen, finishMode, out status);

                destLen = decoder.mDicPos;

                if (res == SZ_OK && status == ELzmaStatus.LZMA_STATUS_NEEDS_MORE_INPUT)
                    res = SZ_ERROR_INPUT_EOF;

                decoder.LzmaDec_FreeProbs(alloc);
                return res;
            }