public ZipOutputStream(Stream baseOutputStream, int bufferSize) : base(baseOutputStream, new Deflater(-1, true), bufferSize) { entries = new ArrayList(); crc = new Crc32(); defaultCompressionLevel = -1; curMethod = CompressionMethod.Deflated; zipComment = new byte[0]; crcPatchPos = -1L; sizePatchPos = -1L; useZip64_ = UseZip64.Dynamic; }
public GZipOutputStream(Stream baseOutputStream, int size = 0x1000) : base(baseOutputStream, new Deflater(-1, true), size) { crc = new Crc32(); }
private bool ReadHeader() { crc = new Crc32(); if (inputBuffer.Available <= 0) { inputBuffer.Fill(); if (inputBuffer.Available <= 0) { return false; } } Crc32 crc32 = new Crc32(); int num = inputBuffer.ReadLeByte(); if (num < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num); if (num != 0x1f) { throw new GZipException("Error GZIP header, first magic byte doesn't match"); } num = inputBuffer.ReadLeByte(); if (num < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } if (num != 0x8b) { throw new GZipException("Error GZIP header, second magic byte doesn't match"); } crc32.Update(num); int num2 = inputBuffer.ReadLeByte(); if (num2 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } if (num2 != 8) { throw new GZipException("Error GZIP header, data not in deflate format"); } crc32.Update(num2); int num3 = inputBuffer.ReadLeByte(); if (num3 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num3); if ((num3 & 0xe0) != 0) { throw new GZipException("Reserved flag bits in GZIP header != 0"); } for (int i = 0; i < 6; i++) { int num5 = inputBuffer.ReadLeByte(); if (num5 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num5); } if ((num3 & 4) != 0) { for (int j = 0; j < 2; j++) { int num7 = inputBuffer.ReadLeByte(); if (num7 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num7); } if ((inputBuffer.ReadLeByte() < 0) || (inputBuffer.ReadLeByte() < 0)) { throw new EndOfStreamException("EOS reading GZIP header"); } int num8 = inputBuffer.ReadLeByte(); int num9 = inputBuffer.ReadLeByte(); if ((num8 < 0) || (num9 < 0)) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num8); crc32.Update(num9); int num10 = (num8 << 8) | num9; for (int k = 0; k < num10; k++) { int num12 = inputBuffer.ReadLeByte(); if (num12 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num12); } } if ((num3 & 8) != 0) { int num13; while ((num13 = inputBuffer.ReadLeByte()) > 0) { crc32.Update(num13); } if (num13 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num13); } if ((num3 & GZipConstants.FCOMMENT) != 0) { int num14; while ((num14 = inputBuffer.ReadLeByte()) > 0) { crc32.Update(num14); } if (num14 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc32.Update(num14); } if ((num3 & 2) != 0) { int num16 = inputBuffer.ReadLeByte(); if (num16 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } int num15 = inputBuffer.ReadLeByte(); if (num15 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } num16 = (num16 << 8) | num15; if (num16 != (((int)crc32.Value) & 0xffff)) { throw new GZipException("Header CRC value mismatch"); } } readGZIPHeader = true; return true; }
public ZipInputStream(Stream baseInputStream, int bufferSize) : base(baseInputStream, new Inflater(true), bufferSize) { crc = new Crc32(); internalReader = ReadingNotAvailable; }
public override void Close() { internalReader = ReadingNotAvailable; crc = null; entry = null; base.Close(); }