private void CompressString(string str)
        {
            MemoryStream memoryStream = new MemoryStream();
            CompressionMethod method = (CompressionMethod)Enum.Parse(typeof(CompressionMethod), CompressionMethods.SelectedValue.ToString(), false);
            CompressionSettings settins = null;
            switch (method)
            {
                case CompressionMethod.Stored:
                    settins = new StoreSettings();
                    break;
                case CompressionMethod.Deflate:
                    settins = new DeflateSettings();
                    break;
                case CompressionMethod.Lzma:
                    settins = new LzmaSettings();
                    break;
            }

            CompressedStream zipOutputStream = new CompressedStream(memoryStream, StreamOperationMode.Write, settins);
            StreamWriter writer = new StreamWriter(zipOutputStream);
            writer.Write(str);
            writer.Flush();

            CompressedText.Text = Convert.ToBase64String(memoryStream.ToArray());
        }
Exemplo n.º 2
0
        private void CompressFile(object obj)
        {
            this.CompressCompressedSize = string.Empty;

            using (Stream compressedStream = new MemoryStream())
            {
                DeflateSettings compressionSettings = new DeflateSettings();

                string compressionLevel = this.CompressionLevelItemsSource[this.SelectedCompressionLevelIndex];
                compressionSettings.CompressionLevel = (CompressionLevel)Enum.Parse(typeof(CompressionLevel), compressionLevel);

                using (ZipArchive archive = new ZipArchive(compressedStream, ZipArchiveMode.Create, true, null, compressionSettings, null))
                {
                    using (Stream uncompressedFileStream = GetEmbeddedResourceStream(UncompressedFileName))
                    {
                        using (ZipArchiveEntry entry = archive.CreateEntry(UncompressedFileName))
                        {
                            using (Stream entryStream = entry.Open())
                            {
                                uncompressedFileStream.CopyTo(entryStream);
                            }
                        }
                    }
                }

                this.CompressCompressedSize = string.Format(FileSizeSringFormat, compressedStream.Length);
            }
        }
Exemplo n.º 3
0
 private void DeflateSettings()
 {
     #region radziplibrary-compression-settings_0
     DeflateSettings compressionSettings = new DeflateSettings();
     compressionSettings.CompressionLevel = CompressionLevel.Best;
     compressionSettings.HeaderType       = CompressedStreamHeader.ZLib;
     #endregion
 }
Exemplo n.º 4
0
        internal override void CopyFrom(CompressionSettings baseSettings)
        {
            DeflateSettings deflateSettings = baseSettings as DeflateSettings;

            if (deflateSettings == null)
            {
                return;
            }
            this.HeaderType       = deflateSettings.HeaderType;
            this.CompressionLevel = deflateSettings.CompressionLevel;
        }
Exemplo n.º 5
0
        public static void CreateFromDirectory(
            string sourceDirectoryName,
            string destinationArchiveFileName,
            CompressionLevel compressionLevel,
            bool includeBaseDirectory)
        {
            DeflateSettings deflateSettings = new DeflateSettings()
            {
                CompressionLevel = compressionLevel, HeaderType = CompressedStreamHeader.None
            };

            ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName, (CompressionSettings)deflateSettings, includeBaseDirectory, (Encoding)null);
        }
Exemplo n.º 6
0
        public static ZipArchiveEntry CreateEntryFromFile(
            ZipArchive destination,
            string sourceFileName,
            string entryName,
            CompressionLevel compressionLevel)
        {
            DeflateSettings deflateSettings = new DeflateSettings()
            {
                CompressionLevel = compressionLevel, HeaderType = CompressedStreamHeader.None
            };

            return(ZipFile.CreateEntryFromFile(destination, sourceFileName, entryName, (CompressionSettings)deflateSettings));
        }
Exemplo n.º 7
0
 public DeflateTransformBase(DeflateSettings settings)
 {
     this.Settings = settings;
 }