Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public GZipOutputStream(Stream baseOutputStream, int size = 0x1000)
     : base(baseOutputStream, new Deflater(-1, true), size)
 {
     _crc = new Crc32();
 }
Esempio n. 3
0
 public ZipInputStream(Stream baseInputStream, int bufferSize)
     : base(baseInputStream, new Inflater(true), bufferSize)
 {
     _crc = new Crc32();
     _internalReader = ReadingNotAvailable;
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 public override void Close()
 {
     _internalReader = ReadingNotAvailable;
     _crc = null;
     _entry = null;
     base.Close();
 }