예제 #1
0
        public ZipArchive(
            Stream stream,
            ZipArchiveMode mode,
            bool leaveOpen,
            Encoding entryNameEncoding,
            CompressionSettings compressionSettings,
            EncryptionSettings encryptionSettings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            this.EntryNameEncoding = entryNameEncoding;
            if (compressionSettings == null)
            {
                compressionSettings = (CompressionSettings) new DeflateSettings()
                {
                    HeaderType = CompressedStreamHeader.None
                }
            }
            ;
            this.CompressionSettings = compressionSettings;
            this.CompressionSettings.PrepareForZip((CentralDirectoryHeader)null);
            this.EncryptionSettings = encryptionSettings;
            this.Init(stream, mode, leaveOpen);
        }

        ~ZipArchive()
        {
            this.Dispose(false);
        }
예제 #2
0
 internal ZipArchiveEntry(ZipArchive archive, string entryName, CompressionSettings settings)
     : this(archive, entryName)
 {
     this.settings = settings;
     this.settings.PrepareForZip((CentralDirectoryHeader)null);
     this.CompressionMethod = settings.Method;
 }
예제 #3
0
        internal static CompressionSettings GetCompressionSettings(
            CompressionMethod method,
            CompressionSettings baseSettings)
        {
            CompressionSettings compressionSettings;

            switch (method)
            {
            case CompressionMethod.Stored:
                compressionSettings = (CompressionSettings) new StoreSettings();
                break;

            case CompressionMethod.Deflate:
                compressionSettings = (CompressionSettings) new DeflateSettings();
                break;

            case CompressionMethod.Lzma:
                compressionSettings = (CompressionSettings) new LzmaSettings();
                break;

            default:
                throw new NotSupportedException(string.Format("Compression method {0} is not supported.", (object)method));
            }
            if (baseSettings != null && (object)compressionSettings.GetType() == (object)baseSettings.GetType())
            {
                compressionSettings.CopyFrom(baseSettings);
            }
            return(compressionSettings);
        }
예제 #4
0
        internal static ICompressionAlgorithm GetCompressionAlgorithm(
            CompressionSettings settings)
        {
            ICompressionAlgorithm compressionAlgorithm;

            switch (settings.Method)
            {
            case CompressionMethod.Stored:
                compressionAlgorithm = (ICompressionAlgorithm) new StoreAlgorithm();
                break;

            case CompressionMethod.Deflate:
                compressionAlgorithm = (ICompressionAlgorithm) new DeflateAlgorithm();
                break;

            case CompressionMethod.Lzma:
                compressionAlgorithm = (ICompressionAlgorithm) new LzmaAlgorithm();
                break;

            default:
                throw new NotSupportedException(string.Format("Compression method {0} is not supported.", (object)settings));
            }
            compressionAlgorithm?.Initialize(settings);
            return(compressionAlgorithm);
        }
예제 #5
0
 public CompressedStream(
     Stream baseStream,
     StreamOperationMode mode,
     CompressionSettings settings)
     : this(baseStream, mode, settings, true, (EncryptionSettings)null)
 {
 }
예제 #6
0
 public void Initialize(CompressionSettings settings)
 {
     this.deflateSettings = settings as DeflateSettings;
     if (this.deflateSettings == null)
     {
         throw new ArgumentException("Wrong settings type.");
     }
 }
예제 #7
0
 internal ZipArchiveEntry(ZipArchive archive, CentralDirectoryHeader header)
 {
     this.Archive  = archive;
     this.header   = header;
     this.settings = ZipHelper.GetCompressionSettings((CompressionMethod)this.header.CompressionMethod, this.Archive.CompressionSettings);
     this.settings.PrepareForZip((CentralDirectoryHeader)null);
     this.existedInArchive = true;
 }
예제 #8
0
        public ZipArchiveEntry CreateEntry(
            string entryName,
            CompressionSettings settings)
        {
            ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(this, entryName, settings);

            this.entries.Add(zipArchiveEntry.FullName, zipArchiveEntry);
            return(zipArchiveEntry);
        }
예제 #9
0
        public CompressedStream(
            Stream baseStream,
            StreamOperationMode mode,
            CompressionSettings settings,
            bool useCrc32,
            EncryptionSettings encryptionSettings)
            : base(baseStream, mode)
        {
            baseStream = encryptionSettings != null ? (Stream) new CryptoStream(baseStream, mode, PlatformSettings.Manager.GetCryptoProvider(encryptionSettings)) : baseStream;
            ICompressionAlgorithm compressionAlgorithm = ZipHelper.GetCompressionAlgorithm(settings);
            IChecksumAlgorithm    checksumAlgorithm    = useCrc32 ? (IChecksumAlgorithm) new Crc32() : (IChecksumAlgorithm) new Adler32();

            this.Initialize(baseStream, compressionAlgorithm, checksumAlgorithm);
        }
예제 #10
0
 internal ZipArchiveEntry(ZipArchive archive, string entryName)
 {
     this.Archive  = archive;
     this.settings = this.Archive.CompressionSettings;
     this.header   = new CentralDirectoryHeader();
     this.header.VersionNeededToExtract = (ushort)10;
     this.header.GeneralPurposeBitFlag  = (ushort)8;
     if (this.Archive.EncryptionSettings is DefaultEncryptionSettings)
     {
         this.header.GeneralPurposeBitFlag |= (ushort)1;
         this.ValidateVersionNeeded(VersionNeededToExtract.Deflate);
     }
     this.FullName      = entryName;
     this.LastWriteTime = DateTimeOffset.Now;
 }
예제 #11
0
 internal virtual void CopyFrom(CompressionSettings baseSettings)
 {
 }