Ejemplo n.º 1
0
 public ZipOutputStream(Stream baseStream, CompressionMethod method)
     : base(baseStream, StreamOperationMode.Write, ZipHelper.GetCompressionSettings(method, (CompressionSettings)null), false, (EncryptionSettings)null)
 {
 }
Ejemplo n.º 2
0
 private void ReadEndOfCentralDirectory()
 {
     try
     {
         this.Reader.BaseStream.Seek(-18L, SeekOrigin.End);
         if (!ZipHelper.SeekBackwardsToSignature(this.Reader.BaseStream, 101010256U))
         {
             throw new InvalidDataException("End of central directory not found.");
         }
         long position = this.Reader.BaseStream.Position;
         this.endOfCentralDirectoryRecord = new EndOfCentralDirectoryRecord();
         if (!this.endOfCentralDirectoryRecord.TryReadBlock(this.archiveReader))
         {
             throw new InvalidDataException("End of central directory not found.");
         }
         if ((int)this.endOfCentralDirectoryRecord.NumberOfThisDisk != (int)this.endOfCentralDirectoryRecord.NumberOfTheDiskWithTheStartOfTheCentralDirectory)
         {
             throw new InvalidDataException("Splitted archive is not supported.");
         }
         if ((int)this.endOfCentralDirectoryRecord.NumberOfEntriesInTheCentralDirectory != (int)this.endOfCentralDirectoryRecord.NumberOfEntriesInTheCentralDirectoryOnThisDisk)
         {
             throw new InvalidDataException("Splitted archive is not supported.");
         }
         if (this.endOfCentralDirectoryRecord.NumberOfThisDisk == ushort.MaxValue || this.endOfCentralDirectoryRecord.OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber == uint.MaxValue || this.endOfCentralDirectoryRecord.NumberOfEntriesInTheCentralDirectory == ushort.MaxValue)
         {
             this.Reader.BaseStream.Seek(position - 16L, SeekOrigin.Begin);
             if (ZipHelper.SeekBackwardsToSignature(this.Reader.BaseStream, 117853008U))
             {
                 this.zip64EndOfCentralDirectoryLocator = new Zip64EndOfCentralDirectoryLocator();
                 if (!this.zip64EndOfCentralDirectoryLocator.TryReadBlock(this.archiveReader))
                 {
                     throw new InvalidDataException("ZIP64 End of central directory locator not found.");
                 }
                 if (this.zip64EndOfCentralDirectoryLocator.RelativeOffsetOfTheZip64EndOfCentralDirectoryRecord > (ulong)long.MaxValue)
                 {
                     throw new InvalidDataException("Relative offset of the Zip64 End Of Central Directory Record is too big.");
                 }
                 this.Reader.BaseStream.Seek((long)this.zip64EndOfCentralDirectoryLocator.RelativeOffsetOfTheZip64EndOfCentralDirectoryRecord, SeekOrigin.Begin);
                 this.zip64EndOfCentralDirectoryRecord = new Zip64EndOfCentralDirectoryRecord();
                 if (!this.zip64EndOfCentralDirectoryRecord.TryReadBlock(this.archiveReader))
                 {
                     throw new InvalidDataException("Zip64 End Of Central Directory Record not found.");
                 }
                 if (this.zip64EndOfCentralDirectoryRecord.NumberOfEntriesInTheCentralDirectory > (ulong)long.MaxValue)
                 {
                     throw new InvalidDataException("Number of entries is too big.");
                 }
                 if (this.zip64EndOfCentralDirectoryRecord.OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber > (ulong)long.MaxValue)
                 {
                     throw new InvalidDataException("Relative offset of the Central Directory Start is too big.");
                 }
                 if ((long)this.zip64EndOfCentralDirectoryRecord.NumberOfEntriesInTheCentralDirectory != (long)this.zip64EndOfCentralDirectoryRecord.NumberOfEntriesInTheCentralDirectoryOnThisDisk)
                 {
                     throw new InvalidDataException("Splitted archive is not supported.");
                 }
             }
         }
         if (this.CentralDirectoryStart > this.Reader.BaseStream.Length)
         {
             throw new InvalidDataException("Relative offset of the Central Directory Start is too big.");
         }
     }
     catch (EndOfStreamException ex)
     {
         throw new InvalidDataException("Archive corrupted", (Exception)ex);
     }
     catch (IOException ex)
     {
         throw new InvalidDataException("Archive corrupted", (Exception)ex);
     }
 }