private void complete() { this.storedCombinedCRC = bsGetInt(); this.currentState = CState.EOF; this.data = null; if (this.storedCombinedCRC != this.computedCombinedCRC) { var msg = String.Format("BZip2 CRC error (expected {0:X8}, computed {1:X8})", this.storedCombinedCRC, this.computedCombinedCRC); throw new IOException(msg); } }
void InitBlock() { char magic0 = bsGetUByte(); char magic1 = bsGetUByte(); char magic2 = bsGetUByte(); char magic3 = bsGetUByte(); char magic4 = bsGetUByte(); char magic5 = bsGetUByte(); if (magic0 == 0x17 && magic1 == 0x72 && magic2 == 0x45 && magic3 == 0x38 && magic4 == 0x50 && magic5 == 0x90) { complete(); // end of file } else if (magic0 != 0x31 || magic1 != 0x41 || magic2 != 0x59 || magic3 != 0x26 || magic4 != 0x53 || magic5 != 0x59) { this.currentState = CState.EOF; var msg = String.Format("bad block header at offset 0x{0:X}", this.input.Position); throw new IOException(msg); } else { this.storedBlockCRC = bsGetInt(); // Console.WriteLine(" stored block CRC : {0:X8}", this.storedBlockCRC); this.blockRandomised = (GetBits(1) == 1); // Lazily allocate data if (this.data == null) { this.data = new DecompressionState(this.blockSize100k); } // currBlockNo++; getAndMoveToFrontDecode(); this.crc.Reset(); this.currentState = CState.START_BLOCK; } }
public override void Close() { Stream stream = this.input; if (stream != null) { try { if (!this._leaveOpen) { stream.Close(); } } finally { this.data = null; this.input = null; } } }
/// <summary> /// Close the stream. /// </summary> public override void Close() { Stream inShadow = this.input; if (inShadow != null) { try { if (!this._leaveOpen) { inShadow.Close(); } } finally { this.data = null; this.input = null; } } }
private void SetupBlock() { if (this.data == null) { return; } BZip2InputStream.DecompressionState decompressionState = this.data; int[] array = decompressionState.initTT(this.last + 1); int i; for (i = 0; i <= 255; i++) { if (decompressionState.unzftab[i] < 0 || decompressionState.unzftab[i] > this.last) { throw new Exception("BZ_DATA_ERROR"); } } decompressionState.cftab[0] = 0; for (i = 1; i <= 256; i++) { decompressionState.cftab[i] = decompressionState.unzftab[i - 1]; } for (i = 1; i <= 256; i++) { decompressionState.cftab[i] += decompressionState.cftab[i - 1]; } for (i = 0; i <= 256; i++) { if (decompressionState.cftab[i] < 0 || decompressionState.cftab[i] > this.last + 1) { string message = string.Format("BZ_DATA_ERROR: cftab[{0}]={1} last={2}", i, decompressionState.cftab[i], this.last); throw new Exception(message); } } for (i = 1; i <= 256; i++) { if (decompressionState.cftab[i - 1] > decompressionState.cftab[i]) { throw new Exception("BZ_DATA_ERROR"); } } i = 0; int num = this.last; while (i <= num) { array[decompressionState.cftab[(int)(decompressionState.ll8[i] & 255)]++] = i; i++; } if (this.origPtr < 0 || this.origPtr >= array.Length) { throw new IOException("stream corrupted"); } this.su_tPos = array[this.origPtr]; this.su_count = 0; this.su_i2 = 0; this.su_ch2 = 256; if (this.blockRandomised) { this.su_rNToGo = 0; this.su_rTPos = 0; this.SetupRandPartA(); } else { this.SetupNoRandPartA(); } }
private void getAndMoveToFrontDecode() { BZip2InputStream.DecompressionState decompressionState = this.data; this.origPtr = this.GetBits(24); if (this.origPtr < 0) { throw new IOException("BZ_DATA_ERROR"); } if (this.origPtr > 10 + BZip2.BlockSizeMultiple * this.blockSize100k) { throw new IOException("BZ_DATA_ERROR"); } this.recvDecodingTables(); byte[] getAndMoveToFrontDecode_yy = decompressionState.getAndMoveToFrontDecode_yy; int num = this.blockSize100k * BZip2.BlockSizeMultiple; int num2 = 256; while (--num2 >= 0) { getAndMoveToFrontDecode_yy[num2] = (byte)num2; decompressionState.unzftab[num2] = 0; } int num3 = 0; int num4 = BZip2.G_SIZE - 1; int num5 = this.nInUse + 1; int num6 = this.getAndMoveToFrontDecode0(0); int num7 = this.bsBuff; int i = this.bsLive; int num8 = -1; int num9 = (int)(decompressionState.selector[num3] & 255); int[] array = decompressionState.gBase[num9]; int[] array2 = decompressionState.gLimit[num9]; int[] array3 = decompressionState.gPerm[num9]; int num10 = decompressionState.gMinlen[num9]; while (num6 != num5) { if (num6 == (int)BZip2.RUNA || num6 == (int)BZip2.RUNB) { int num11 = -1; int num12 = 1; while (true) { if (num6 == (int)BZip2.RUNA) { num11 += num12; } else { if (num6 != (int)BZip2.RUNB) { break; } num11 += num12 << 1; } if (num4 == 0) { num4 = BZip2.G_SIZE - 1; num9 = (int)(decompressionState.selector[++num3] & 255); array = decompressionState.gBase[num9]; array2 = decompressionState.gLimit[num9]; array3 = decompressionState.gPerm[num9]; num10 = decompressionState.gMinlen[num9]; } else { num4--; } int num13 = num10; while (i < num13) { int num14 = this.input.ReadByte(); if (num14 < 0) { goto IL_1EC; } num7 = (num7 << 8 | num14); i += 8; } int j = num7 >> i - num13 & (1 << num13) - 1; i -= num13; while (j > array2[num13]) { num13++; while (i < 1) { int num15 = this.input.ReadByte(); if (num15 < 0) { goto IL_257; } num7 = (num7 << 8 | num15); i += 8; } i--; j = (j << 1 | (num7 >> i & 1)); } num6 = array3[j - array[num13]]; num12 <<= 1; } byte b = decompressionState.seqToUnseq[(int)getAndMoveToFrontDecode_yy[0]]; decompressionState.unzftab[(int)(b & 255)] += num11 + 1; while (num11-- >= 0) { decompressionState.ll8[++num8] = b; } if (num8 >= num) { throw new IOException("block overrun"); } continue; IL_1EC: throw new IOException("unexpected end of stream"); IL_257: throw new IOException("unexpected end of stream"); } if (++num8 >= num) { throw new IOException("block overrun"); } byte b2 = getAndMoveToFrontDecode_yy[num6 - 1]; decompressionState.unzftab[(int)(decompressionState.seqToUnseq[(int)b2] & 255)]++; decompressionState.ll8[num8] = decompressionState.seqToUnseq[(int)b2]; if (num6 <= 16) { int k = num6 - 1; while (k > 0) { getAndMoveToFrontDecode_yy[k] = getAndMoveToFrontDecode_yy[--k]; } } else { Buffer.BlockCopy(getAndMoveToFrontDecode_yy, 0, getAndMoveToFrontDecode_yy, 1, num6 - 1); } getAndMoveToFrontDecode_yy[0] = b2; if (num4 == 0) { num4 = BZip2.G_SIZE - 1; num9 = (int)(decompressionState.selector[++num3] & 255); array = decompressionState.gBase[num9]; array2 = decompressionState.gLimit[num9]; array3 = decompressionState.gPerm[num9]; num10 = decompressionState.gMinlen[num9]; } else { num4--; } int num16 = num10; while (i < num16) { int num17 = this.input.ReadByte(); if (num17 < 0) { throw new IOException("unexpected end of stream"); } num7 = (num7 << 8 | num17); i += 8; } int l = num7 >> i - num16 & (1 << num16) - 1; i -= num16; while (l > array2[num16]) { num16++; while (i < 1) { int num18 = this.input.ReadByte(); if (num18 < 0) { throw new IOException("unexpected end of stream"); } num7 = (num7 << 8 | num18); i += 8; } i--; l = (l << 1 | (num7 >> i & 1)); } num6 = array3[l - array[num16]]; } this.last = num8; this.bsLive = i; this.bsBuff = num7; }
private void recvDecodingTables() { BZip2InputStream.DecompressionState decompressionState = this.data; bool[] inUse = decompressionState.inUse; byte[] recvDecodingTables_pos = decompressionState.recvDecodingTables_pos; int num = 0; for (int i = 0; i < 16; i++) { if (this.bsGetBit()) { num |= 1 << i; } } int num2 = 256; while (--num2 >= 0) { inUse[num2] = false; } for (int j = 0; j < 16; j++) { if ((num & 1 << j) != 0) { int num3 = j << 4; for (int k = 0; k < 16; k++) { if (this.bsGetBit()) { inUse[num3 + k] = true; } } } } this.MakeMaps(); int num4 = this.nInUse + 2; int bits = this.GetBits(3); int bits2 = this.GetBits(15); for (int l = 0; l < bits2; l++) { int num5 = 0; while (this.bsGetBit()) { num5++; } decompressionState.selectorMtf[l] = (byte)num5; } int num6 = bits; while (--num6 >= 0) { recvDecodingTables_pos[num6] = (byte)num6; } for (int m = 0; m < bits2; m++) { int n = (int)decompressionState.selectorMtf[m]; byte b = recvDecodingTables_pos[n]; while (n > 0) { recvDecodingTables_pos[n] = recvDecodingTables_pos[n - 1]; n--; } recvDecodingTables_pos[0] = b; decompressionState.selector[m] = b; } char[][] temp_charArray2d = decompressionState.temp_charArray2d; for (int num7 = 0; num7 < bits; num7++) { int num8 = this.GetBits(5); char[] array = temp_charArray2d[num7]; for (int num9 = 0; num9 < num4; num9++) { while (this.bsGetBit()) { num8 += ((!this.bsGetBit()) ? 1 : -1); } array[num9] = (char)num8; } } this.createHuffmanDecodingTables(num4, bits); }