Ejemplo n.º 1
0
 private int _ExtractOne(Stream output)
 {
     lock (_streamLock)
     {
         Stream input = this.ArchiveStream;
         input.Seek(this.__FileDataPosition, SeekOrigin.Begin);
         byte[] bytes = new byte[0x2200];
         int LeftToRead = (this.CompressionMethod == 8) ? this.UncompressedSize : this._CompressedFileDataSize;
         Stream input3 = (this.CompressionMethod == 8) ? new DeflateStream(input, CompressionMode.Decompress, true) : input;
         using (CrcCalculatorStream s1 = new CrcCalculatorStream(input3))
         {
             while (LeftToRead > 0)
             {
                 int len = (LeftToRead > bytes.Length) ? bytes.Length : LeftToRead;
                 int n = s1.Read(bytes, 0, len);
                 this._CheckRead(n);
                 output.Write(bytes, 0, n);
                 LeftToRead -= n;
             }
             return s1.Crc32;
         }
     }
 }
Ejemplo n.º 2
0
 private void _WriteFileData(Stream s)
 {
     Stream input = null;
     CrcCalculatorStream input1 = null;
     CountingStream counter = null;
     try
     {
         this.__FileDataPosition = s.Position;
     }
     catch
     {
     }
     try
     {
         if (this._sourceStream != null)
         {
             this._sourceStream.Position = 0L;
             input = this._sourceStream;
         }
         else
         {
             input = File.OpenRead(this.LocalFileName);
         }
         input1 = new CrcCalculatorStream(input);
         counter = new CountingStream(s);
         Stream output1 = counter;
         Stream output2 = null;
         bool mustCloseDeflateStream = false;
         if (this.CompressionMethod == 8)
         {
             output2 = new DeflateStream(output1, CompressionMode.Compress, true);
             mustCloseDeflateStream = true;
         }
         else
         {
             output2 = output1;
         }
         byte[] buffer = new byte[0x2200];
         for (int n = input1.Read(buffer, 0, 0x2200); n > 0; n = input1.Read(buffer, 0, 0x2200))
         {
             output2.Write(buffer, 0, n);
         }
         if (mustCloseDeflateStream)
         {
             output2.Close();
         }
     }
     finally
     {
         if ((this._sourceStream == null) && (input != null))
         {
             input.Close();
             input.Dispose();
         }
     }
     this._UncompressedSize = input1.TotalBytesSlurped;
     this._CompressedSize = counter.BytesWritten;
     this._Crc32 = input1.Crc32;
     int i = 8;
     this._EntryHeader[i++] = (byte) (this.CompressionMethod & 0xff);
     this._EntryHeader[i++] = (byte) ((this.CompressionMethod & 0xff00) >> 8);
     i = 14;
     this._EntryHeader[i++] = (byte) (this._Crc32 & 0xff);
     this._EntryHeader[i++] = (byte) ((this._Crc32 & 0xff00) >> 8);
     this._EntryHeader[i++] = (byte) ((this._Crc32 & 0xff0000) >> 0x10);
     this._EntryHeader[i++] = (byte) ((this._Crc32 & 0xff000000L) >> 0x18);
     this._EntryHeader[i++] = (byte) (this._CompressedSize & 0xff);
     this._EntryHeader[i++] = (byte) ((this._CompressedSize & 0xff00) >> 8);
     this._EntryHeader[i++] = (byte) ((this._CompressedSize & 0xff0000) >> 0x10);
     this._EntryHeader[i++] = (byte) ((this._CompressedSize & 0xff000000L) >> 0x18);
     this._EntryHeader[i++] = (byte) (this._UncompressedSize & 0xff);
     this._EntryHeader[i++] = (byte) ((this._UncompressedSize & 0xff00) >> 8);
     this._EntryHeader[i++] = (byte) ((this._UncompressedSize & 0xff0000) >> 0x10);
     this._EntryHeader[i++] = (byte) ((this._UncompressedSize & 0xff000000L) >> 0x18);
     if (s.CanSeek)
     {
         s.Seek((long) this._RelativeOffsetOfHeader, SeekOrigin.Begin);
         s.Write(this._EntryHeader, 0, this._EntryHeader.Length);
         CountingStream s1 = s as CountingStream;
         if (s1 != null)
         {
             s1.Adjust(this._EntryHeader.Length);
         }
         s.Seek((long) this._CompressedSize, SeekOrigin.Current);
     }
     else
     {
         if ((this._BitField & 8) != 8)
         {
             throw new ZipException("Logic error.");
         }
         byte[] Descriptor = new byte[0x10];
         i = 0;
         int sig = 0x8074b50;
         Descriptor[i++] = (byte) (sig & 0xff);
         Descriptor[i++] = (byte) ((sig & 0xff00) >> 8);
         Descriptor[i++] = (byte) ((sig & 0xff0000) >> 0x10);
         Descriptor[i++] = (byte) ((sig & 0xff000000L) >> 0x18);
         Descriptor[i++] = (byte) (this._Crc32 & 0xff);
         Descriptor[i++] = (byte) ((this._Crc32 & 0xff00) >> 8);
         Descriptor[i++] = (byte) ((this._Crc32 & 0xff0000) >> 0x10);
         Descriptor[i++] = (byte) ((this._Crc32 & 0xff000000L) >> 0x18);
         Descriptor[i++] = (byte) (this._CompressedSize & 0xff);
         Descriptor[i++] = (byte) ((this._CompressedSize & 0xff00) >> 8);
         Descriptor[i++] = (byte) ((this._CompressedSize & 0xff0000) >> 0x10);
         Descriptor[i++] = (byte) ((this._CompressedSize & 0xff000000L) >> 0x18);
         Descriptor[i++] = (byte) (this._UncompressedSize & 0xff);
         Descriptor[i++] = (byte) ((this._UncompressedSize & 0xff00) >> 8);
         Descriptor[i++] = (byte) ((this._UncompressedSize & 0xff0000) >> 0x10);
         Descriptor[i++] = (byte) ((this._UncompressedSize & 0xff000000L) >> 0x18);
         s.Write(Descriptor, 0, Descriptor.Length);
     }
 }