public ZipInputStream(Stream baseInputStream, int bufferSize) : base(baseInputStream, new Inflater(true), bufferSize) { this.crc = new Crc32(); this.internalReader = new ReadDataHandler(this.ReadingNotAvailable); }
private static void ZipSetp(string strDirectory, ZipOutputStream s, string parentPath) { if (strDirectory[strDirectory.Length - 1] != Path.DirectorySeparatorChar) { strDirectory = strDirectory + Path.DirectorySeparatorChar; } Crc32 crc = new Crc32(); string[] fileSystemEntries = Directory.GetFileSystemEntries(strDirectory); foreach (string str in fileSystemEntries) { if (Directory.Exists(str)) { string str2 = parentPath; str2 = str2 + str.Substring(str.LastIndexOf(@"\") + 1) + @"\"; ZipSetp(str, s, str2); } else { using (FileStream stream = File.OpenRead(str)) { byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(parentPath + str.Substring(str.LastIndexOf(@"\") + 1)) { DateTime = DateTime.Now, Size = stream.Length }; stream.Close(); crc.Reset(); crc.Update(buffer); entry.Crc = crc.Value; s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); } } } }
public override void Close() { this.internalReader = new ReadDataHandler(this.ReadingNotAvailable); this.crc = null; this.entry = null; base.Close(); }
private bool ReadHeader() { int num4; int num5; this.crc = new Crc32(); if (base.inputBuffer.Available <= 0) { base.inputBuffer.Fill(); if (base.inputBuffer.Available <= 0) { return false; } } Crc32 crc = new Crc32(); int num = base.inputBuffer.ReadLeByte(); if (num < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num); if (num != 0x1f) { throw new GZipException("Error GZIP header, first magic byte doesn't match"); } num = base.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"); } crc.Update(num); int num2 = base.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"); } crc.Update(num2); int num3 = base.inputBuffer.ReadLeByte(); if (num3 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num3); if ((num3 & 0xe0) != 0) { throw new GZipException("Reserved flag bits in GZIP header != 0"); } for (num4 = 0; num4 < 6; num4++) { num5 = base.inputBuffer.ReadLeByte(); if (num5 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num5); } if ((num3 & 4) != 0) { for (num4 = 0; num4 < 2; num4++) { num5 = base.inputBuffer.ReadLeByte(); if (num5 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num5); } if ((base.inputBuffer.ReadLeByte() < 0) || (base.inputBuffer.ReadLeByte() < 0)) { throw new EndOfStreamException("EOS reading GZIP header"); } int num6 = base.inputBuffer.ReadLeByte(); int num7 = base.inputBuffer.ReadLeByte(); if ((num6 < 0) || (num7 < 0)) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num6); crc.Update(num7); int num8 = (num6 << 8) | num7; for (num4 = 0; num4 < num8; num4++) { num5 = base.inputBuffer.ReadLeByte(); if (num5 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num5); } } if ((num3 & 8) != 0) { while ((num5 = base.inputBuffer.ReadLeByte()) > 0) { crc.Update(num5); } if (num5 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num5); } if ((num3 & 0x10) != 0) { while ((num5 = base.inputBuffer.ReadLeByte()) > 0) { crc.Update(num5); } if (num5 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } crc.Update(num5); } if ((num3 & 2) != 0) { int num10 = base.inputBuffer.ReadLeByte(); if (num10 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } int num9 = base.inputBuffer.ReadLeByte(); if (num9 < 0) { throw new EndOfStreamException("EOS reading GZIP header"); } num10 = (num10 << 8) | num9; if (num10 != (((int) crc.Value) & 0xffff)) { throw new GZipException("Header CRC value mismatch"); } } this.readGZIPHeader = true; return true; }