当前位置: 首页>>代码示例>>C#>>正文


C# Zlib.DeflateStream类代码示例

本文整理汇总了C#中Ionic.Zlib.DeflateStream的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream类的具体用法?C# DeflateStream怎么用?C# DeflateStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DeflateStream类属于Ionic.Zlib命名空间,在下文中一共展示了DeflateStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

 internal void Read()
 {
     try
     {
         using (FileStream fileStream = File.OpenRead(this.Name))
         {
             using (DeflateStream deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress))
             {
                 using (BinaryReader binaryReader = new BinaryReader(deflateStream))
                 {
                     int num = (int)binaryReader.ReadByte();
                     for (int i = 0; i < num; i++)
                     {
                         this.AddFile(binaryReader.ReadString(), binaryReader.ReadBytes(binaryReader.ReadInt32()));
                     }
                 }
                 deflateStream.Dispose();
             }
         }
     }
     catch
     {
         this.InvalidFile = true;
     }
 }
开发者ID:CXUtk,项目名称:TmodKiller,代码行数:25,代码来源:TmodIO.cs

示例2: Read

		internal static ZipFile Read(string name, Task task, DoWorkArgs progress, ProgressChangedArgs args)
		{
			ZipFile zip = new ZipFile(name);
			using (FileStream fileStream = File.OpenRead(name))
			{
				using (DeflateStream decompress = new DeflateStream(fileStream, CompressionMode.Decompress))
				{
					using (BinaryReader reader = new BinaryReader(decompress))
					{
						int count = reader.ReadByte();
						for (int k = 0; k < count; k++)
						{
							string fileName = reader.ReadString();
							if (task != null)
							{
								args.message = "Reading " + fileName + "...";
								task.ReportProgress(progress.background, -1, args);
							}
							byte[] buffer = reader.ReadBytes(reader.ReadInt32());
							zip[fileName] = buffer;
						}
					}
				}
			}
			return zip;
		}
开发者ID:DrakoGlyph,项目名称:tModLoader,代码行数:26,代码来源:ZipFile.cs

示例3: zlibDeflate

 public static void zlibDeflate(
     string pathInput,
     string pathOutput,
     CompressionMode mode,
     CompressionLevel level
 )
 {
     using (Stream input = File.OpenRead(pathInput))
     using (Stream output = File.Create(pathOutput))
     using (Stream deflateStream = new DeflateStream(
         mode == CompressionMode.Compress ? output : input,
         mode, level, true))
     {
         byte[] buff = new byte[ZLIB_BUFF_SIZE];
         int n = 0;
         Stream toRead = mode == CompressionMode.Compress ?
             input : deflateStream;
         Stream toWrite = mode == CompressionMode.Compress ?
             deflateStream : output;
         while (0 != (n = toRead.Read(buff, 0, buff.Length)))
         {
             toWrite.Write(buff, 0, n);
         }
         deflateStream.Close();
         input.Close();
         output.Close();
     }
 }
开发者ID:alejandro-varela,项目名称:AleNet,代码行数:28,代码来源:ZlibHelper.cs

示例4: Compress

        /// <summary>
        /// 지정된 데이타를 압축한다.
        /// </summary>
        /// <param name="input">압축할 Data</param>
        /// <returns>압축된 Data</returns>
        public override byte[] Compress(byte[] input) {
            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressStartMsg);

            // check input data
            if(input.IsZeroLength()) {
                if(IsDebugEnabled)
                    log.Debug(CompressorTool.SR.InvalidInputDataMsg);

                return CompressorTool.EmptyBytes;
            }

            byte[] output;
            using(var outStream = new MemoryStream()) {
                using(var deflate = new DeflateStream(outStream, CompressionMode.Compress, CompressionLevel.BestSpeed)) {
                    deflate.Write(input, 0, input.Length);
                }
                output = outStream.ToArray();
            }

            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);

            return output;
        }
开发者ID:debop,项目名称:NFramework,代码行数:30,代码来源:IonicDeflateCompressor.cs

示例5: Write

		internal void Write(Task task, DoWorkArgs progress, ProgressChangedArgs args)
		{
			using (FileStream fileStream = File.Create(this.name))
			{
				using (DeflateStream compress = new DeflateStream(fileStream, CompressionMode.Compress))
				{
					using (BinaryWriter writer = new BinaryWriter(compress))
					{
						writer.Write((byte)this.files.Count);
						foreach (string file in this.files.Keys)
						{
							if (task != null)
							{
								args.message = "Saving " + file + "...";
								task.ReportProgress(progress.background, -1, args);
							}
							writer.Write(file);
							writer.Write(this.files[file].Length);
							writer.Write(this.files[file]);
						}
						if (task != null)
						{
							args.message = "Done";
							task.ReportProgress(progress.background, -1, args);
						}
					}
				}
			}
		}
开发者ID:DrakoGlyph,项目名称:tModLoader,代码行数:29,代码来源:ZipFile.cs

示例6: Compact

        /// <summary>
        /// Reads all log messages from the supplied file.
        /// </summary>
        public static void Compact(ICollection<string> inputFileNames, string outputFileName)
        {
            LogCollection logs = new LogCollection();

            foreach (var file in inputFileNames)
            {
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    if (stream.ReadBoolean())
                    {
                        //Wrong File Version
                        break;
                    }
                    if (stream.ReadNextByte() != 1)
                    {
                        //Wrong File Version
                        break;
                    }
                    using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
                    using (var bs = new BufferedStream(zipStream, 8192))
                    {
                        while (bs.ReadBoolean())
                        {
                            var message = new LogMessage(bs);
                            logs.Pass1(message);
                        }
                    }
                }
            }

            logs.Compact();
            foreach (var file in inputFileNames)
            {
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    if (stream.ReadBoolean())
                    {
                        //Wrong File Version
                        break;
                    }
                    if (stream.ReadNextByte() != 1)
                    {
                        //Wrong File Version
                        break;
                    }
                    using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
                    using (var bs = new BufferedStream(zipStream, 8192))
                    {
                        while (bs.ReadBoolean())
                        {
                            var message = new LogMessage(bs);
                            logs.Pass2(message);
                        }
                    }
                }
            }
            logs.Save(outputFileName);
        }
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:61,代码来源:LogFileCompactor.cs

示例7: Decompress

 public byte[] Decompress(Stream inputStream)
 {
     using (var deflateStream = new DeflateStream(inputStream, CompressionMode.Decompress))
     using (var outputStream = new MemoryStream())
     {
         deflateStream.WriteTo(outputStream);
         return outputStream.ToArray();
     }
 }
开发者ID:ryanwentzel,项目名称:DesignPatterns,代码行数:9,代码来源:DeflateCompression.cs

示例8: DeflateEncoder

		/// <summary>Deflate encoder, compatible with .NET one but with bettern compression 
		/// ratio (in .NET 4.0, in .NET 4.5 they are identical).</summary>
		/// <param name="input">The input.</param>
		/// <returns>Compressed data.</returns>
		public static byte[] DeflateEncoder(byte[] input)
		{
			using (var ostream = new MemoryStream())
			{
				using (var zstream = new DeflateStream(ostream, CompressionMode.Compress))
				{
					zstream.Write(input, 0, input.Length);
					zstream.Flush();
				}
				return ostream.ToArray();
			}
		}
开发者ID:jinjingcai2014,项目名称:LibZ,代码行数:16,代码来源:DefaultCodecs.cs

示例9: CompressDeflate

        public static byte[] CompressDeflate(byte[] bytes)
        {
            using (var ms = new MemoryStream())
            {
                using (var zip = new DeflateStream(ms, CompressionMode.Compress, true))
                {
                    zip.Write(bytes, 0, bytes.Length);
                }

                return ms.ToArray();
            }
        }
开发者ID:venusdharan,项目名称:Titanium-Web-Proxy,代码行数:12,代码来源:Compression.cs

示例10: DecryptAes128CbcWithGzip

 private static byte[] DecryptAes128CbcWithGzip(byte[] data, byte[] key)
 {
     byte[] gzippedFile;
     using (var cipher = new AesManaged { Mode = CipherMode.CBC, Key = key })
         gzippedFile = cipher.CreateDecryptor().TransformFinalBlock(data, 0, data.Length).Skip(16).ToArray();
     using (var inStream = new MemoryStream(gzippedFile))
     using (var zipStream = new DeflateStream(inStream, CompressionMode.Decompress))
     using (var outStream = new MemoryStream())
     {
         zipStream.CopyTo(outStream);
         return outStream.ToArray();
     }
 }
开发者ID:13xforever,项目名称:DeDRM,代码行数:13,代码来源:Decryptor.cs

示例11: CompressBuffer

 public static byte[] CompressBuffer(byte[] buffer)
 {
     byte[] compressed;
     using (var input = new MemoryStream(buffer))
     using (var compressStream = new MemoryStream())
     using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
     {
         input.CopyTo(compressor);
         compressor.Close();
         compressed = compressStream.ToArray();
     }
     return compressed;
 }
开发者ID:Boblepointu,项目名称:Coob,代码行数:13,代码来源:ZlibHelper.cs

示例12: Deflate

        private static byte[] Deflate(byte[] bytes)
        {
            if (bytes == null) return new byte[0];

            using (var stream = new MemoryStream())
            {
                using (var compressor = new DeflateStream(stream,CompressionMode.Compress, CompressionLevel.BestSpeed))
                {
                    compressor.Write(bytes, 0, bytes.Length);
                }

                return stream.ToArray();
            }
        }
开发者ID:alexvance89,项目名称:tinder-api,代码行数:14,代码来源:DeflateCompressionAttribute.cs

示例13: btnApiAccess_Click

        private async void btnApiAccess_Click(object sender, EventArgs e)
        {
            var claim = await GetClaimsAsync(UserAccessInfo.AccessToken);

            var query = from info in claim where info.Item1 == UGConstants.ClaimTypes.PreferredUserName select info.Item2;
            string userName = string.Empty;
            if (query.Count() > 0)
                userName = query.First();

            var client = new HttpClient();
            client.SetBearerToken(UserAccessInfo.AccessToken);
            client.DefaultRequestHeaders.Add(UGConstants.HTTPHeaders.IOT_CLIENT_ID, IoTClientId);
            client.DefaultRequestHeaders.Add(UGConstants.HTTPHeaders.IOT_CLIENT_SECRET, IoTClientSecret);
            client.DefaultRequestHeaders.Add(UGConstants.ClaimTypes.PreferredUserName, userName);

            BaseMessage msg = new BaseMessage("", "", SSD.Framework.Exceptions.ErrorCode.IsSuccess, "");
            msg.MsgJson = "{\"LocationStoreID\":1,\"ID\":1}";
            StringContent queryString = new StringContent(msg.ToJson());
            var response = await client.PostAsync(APIUri,queryString);

            if (response.IsSuccessStatusCode)
            {
                string contentStr = string.Empty;

                IEnumerable<string> lst;
                if (response.Content.Headers != null
                    && response.Content.Headers.TryGetValues(UGConstants.HTTPHeaders.CONTENT_ENCODING, out lst)
                    && lst.First().ToLower() == "deflate")
                {
                    var bj = await response.Content.ReadAsByteArrayAsync();
                    using (var inStream = new MemoryStream(bj))
                    {
                        using (var bigStreamsss = new DeflateStream(inStream, CompressionMode.Decompress, true))
                        {
                            contentStr = await (new StreamReader(bigStreamsss)).ReadToEndAsync();
                            //using (var bigStreamOut = new MemoryStream())
                            //{
                            //    bigStreamsss.CopyTo(bigStreamOut);
                            //    contentStr = Encoding.UTF8.GetString(bigStreamOut.ToArray(), 0, bigStreamOut.ToArray().Length);
                            //}
                        }

                    }
                }
                else contentStr = await response.Content.ReadAsStringAsync();
                MessageBox.Show(contentStr);
            }
        }
开发者ID:khoainv,项目名称:Framework,代码行数:48,代码来源:frmLogin.cs

示例14: DeflateByte

        public static byte[] DeflateByte(byte[] content)
        {
            if(null==content)
            {
                return null;
            }

            using (var stream = new MemoryStream())
            {
                using (var compressor = new DeflateStream(stream,CompressionMode.Compress,CompressionLevel.BestSpeed))
                {
                    compressor.Write(content,0,content.Length);
                }

                return stream.ToArray();
            }
        }
开发者ID:liujiekm,项目名称:MedicalInsuranceService,代码行数:17,代码来源:DeflateCompressionAttribute.cs

示例15: DecompressDeflate

        public static byte[] DecompressDeflate(Stream input)
        {
            using (var decompressor = new DeflateStream(input, CompressionMode.Decompress))
            {
                var buffer = new byte[BufferSize];

                using (var output = new MemoryStream())
                {
                    int read;
                    while ((read = decompressor.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        output.Write(buffer, 0, read);
                    }
                    return output.ToArray();
                }
            }
        }
开发者ID:venusdharan,项目名称:Titanium-Web-Proxy,代码行数:17,代码来源:Compression.cs


注:本文中的Ionic.Zlib.DeflateStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。