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


C# GZipStream.Flush方法代码示例

本文整理汇总了C#中System.IO.Compression.GZipStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.Flush方法的具体用法?C# GZipStream.Flush怎么用?C# GZipStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Compression.GZipStream的用法示例。


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

示例1: Gzip

 private static int Gzip(Stream stream, FileStream fs)
 {
     int length = 0;
     using (var ms = new MemoryStream())
     {
         byte[] buffer = new byte[BufferSize];
         int count;
         using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
         {
             while ((count = fs.Read(buffer, 0, BufferSize)) > 0)
             {
                 gzip.Write(buffer, 0, count);
             }
             gzip.Flush();
         }
         ms.Seek(0, SeekOrigin.Begin);
         while ((count = ms.Read(buffer, 0, BufferSize)) > 0)
         {
             length += count;
             stream.Write(buffer, 0, count);
         }
         stream.Flush();
     }
     return length;
 }
开发者ID:Muscipular,项目名称:osu-BeatmapTool,代码行数:25,代码来源:Program.cs

示例2: WriteGzip

		public static void WriteGzip(XmlDocument theDoc, Stream theStream)
		{
			var ms = new MemoryStream();
		    var xmlSettings = new XmlWriterSettings
		                          {
		                              Encoding = Encoding.UTF8,
		                              ConformanceLevel = ConformanceLevel.Document,
		                              Indent = false,
		                              NewLineOnAttributes = false,
		                              CheckCharacters = true,
		                              IndentChars = string.Empty
		                          };

		    XmlWriter tw = XmlWriter.Create(ms, xmlSettings);

			theDoc.WriteTo(tw);
			tw.Flush();
			tw.Close();

			byte[] buffer = ms.GetBuffer();

			var compressedzipStream = new GZipStream(theStream, CompressionMode.Compress, true);
			compressedzipStream.Write(buffer, 0, buffer.Length);
			// Close the stream.
			compressedzipStream.Flush();
			compressedzipStream.Close();

			// Force a flush
			theStream.Flush();
		}
开发者ID:kevinpig,项目名称:MyRepository,代码行数:30,代码来源:StudyXmlIo.cs

示例3: ManagedBitmap

        public ManagedBitmap(string fileName)
        {
            try
            {
                byte[] buffer = new byte[1024];
                MemoryStream fd = new MemoryStream();
                Stream fs = File.OpenRead(fileName);
                using (Stream csStream = new GZipStream(fs, CompressionMode.Decompress))
                {
                    int nRead;
                    while ((nRead = csStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fd.Write(buffer, 0, nRead);
                    }
                    csStream.Flush();
                    buffer = fd.ToArray();
                }

                Width = buffer[4] << 8 | buffer[5];
                Height = buffer[6] << 8 | buffer[7];
                _colors = new Color[Width * Height];
                int start = 8;
                for (int i = 0; i < _colors.Length; i++)
                {
                    _colors[i] = Color.FromArgb(buffer[start], buffer[start + 1], buffer[start + 2], buffer[start + 3]);
                    start += 4;
                }
            }
            catch
            {
                LoadedOk = false;
            }
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:33,代码来源:ManagedBitmap.cs

示例4: ProcessAction

        public void ProcessAction(Object eventObject)
        {
            lock (blacklistLock)
            {
                if(blacklist.Contains(eventObject))
                {
                    blacklist.Remove(eventObject);
                    return;
                }
            }

            var memoryStream = new MemoryStream();
            var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress);
            var writer = new StreamWriter(gzipStream);

            serializer.Serialize(writer, eventObject);

            writer.Flush();
            gzipStream.Flush();
            memoryStream.Flush();

            writer.Close();
            gzipStream.Close();
            memoryStream.Close();

            var obj = new EventObject { MessageType = eventObject.GetType().AssemblyQualifiedName, MessageBody = memoryStream.ToArray(), SessionId = sessionId };

            eventRepository.Save(obj);
        }
开发者ID:grozeille,项目名称:chiffrage,代码行数:29,代码来源:EventStoreService.cs

示例5: GZCompress

 public static byte[] GZCompress(byte[] source)
 {
     byte[] buffer;
     if ((source == null) || (source.Length == 0))
     {
         throw new ArgumentNullException("source");
     }
     try
     {
         using (MemoryStream stream = new MemoryStream())
         {
             using (GZipStream stream2 = new GZipStream(stream, CompressionMode.Compress, true))
             {
                 Console.WriteLine("Compression");
                 stream2.Write(source, 0, source.Length);
                 stream2.Flush();
                 stream2.Close();
                 Console.WriteLine("Original size: {0}, Compressed size: {1}", source.Length, stream.Length);
                 stream.Position = 0L;
                 buffer = stream.ToArray();
             }
         }
     }
     catch (Exception exception)
     {
         LoggingService.Error("GZip压缩时出错:", exception);
         buffer = source;
     }
     return buffer;
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:30,代码来源:ZipHelper.cs

示例6: Compression

 private MemoryStream Compression(byte[] bytes)
 {
     MemoryStream ms = new MemoryStream();
     GZipStream gzip = new GZipStream(ms, CompressionLevel.Optimal);
     gzip.Write(bytes, 0, bytes.Length);
     gzip.Flush();
     gzip.Close();
     return ms;
 }
开发者ID:moto2002,项目名称:NewPhoenix,代码行数:9,代码来源:GetConfig.cs

示例7: Zip

 public static byte[] Zip(byte[] bytes)
 {
     using (var destination = new MemoryStream())
     using (var gzip = new GZipStream(destination, CompressionLevel.Fastest, false))
     {
         gzip.Write(bytes, 0, bytes.Length);
         gzip.Flush();
         gzip.Close();
         return destination.ToArray();
     }
 }
开发者ID:jsifantu,项目名称:kafka-net,代码行数:11,代码来源:Protocol.cs

示例8: Compress

 public static byte[] Compress(this byte[] data)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         using (GZipStream zs = new GZipStream(ms, CompressionMode.Compress))
         {
             zs.Write(data, 0, data.Length);
             zs.Flush();
         }
         return ms.ToArray();
     }
 }
开发者ID:bfbd,项目名称:MiniWeb,代码行数:12,代码来源:Compress.cs

示例9: Unzip

 public static byte[] Unzip(byte[] bytes)
 {
     using (var source = new MemoryStream(bytes))
     using (var destination = new MemoryStream())
     using (var gzip = new GZipStream(source, CompressionMode.Decompress, false))
     {
         gzip.CopyTo(destination);
         gzip.Flush();
         gzip.Close();
         return destination.ToArray();
     }
 }
开发者ID:jsifantu,项目名称:kafka-net,代码行数:12,代码来源:Protocol.cs

示例10: Save

        public static void Save(ArpeggioDefinition arpeggio, string fileName)
        {
            Stream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
            GZipStream gzip = new GZipStream(fileStream, CompressionMode.Compress, true);

            SerializationUtils.Serialize(arpeggio, gzip);

            gzip.Flush();
            gzip.Close();
            fileStream.Close();
            fileStream.Dispose();
        }
开发者ID:AugustoRuiz,项目名称:WYZTracker,代码行数:12,代码来源:ArpeggioManager.cs

示例11: GZipCompress

        public static byte[] GZipCompress(byte[] source)
        {
            var memoryStream = new MemoryStream();
            var stream = new GZipStream(memoryStream, CompressionMode.Compress);
            stream.Write(source, 0, source.Length);
            stream.Flush();
            stream.Close();

            //Console.WriteLine("GZip : {0}", memoryStream.ToArray().Length);

            return memoryStream.ToArray();
        }
开发者ID:ZhuGongpu,项目名称:CloudX,代码行数:12,代码来源:CompressionAndDecompressionUtils.cs

示例12: Compress

        public Stream Compress(string content)
        {
            var ms = new MemoryStream();
            using (var zip = new GZipStream(ms, CompressionMode.Compress, true))
            {
                var buffer = Encoding.UTF8.GetBytes(content);
                zip.Write(buffer, 0, buffer.Length);
                zip.Flush();
            }

            ms.Position = 0;
            return ms;
        }
开发者ID:AlexCuse,项目名称:SquishIt.S3,代码行数:13,代码来源:GZipCompressor.cs

示例13: Depress

 /// <summary>
 /// 解压二进制流
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] Depress(byte[] data)
 {
     using (var memoryStream = new MemoryStream(data))
     using (var outStream = new MemoryStream())
     {
         using (var compressionStream = new GZipStream(memoryStream, CompressionMode.Decompress))
         {
             compressionStream.CopyTo(outStream);
             compressionStream.Flush();
         }
         return outStream.ToArray();
     }
 }
开发者ID:CSStudio,项目名称:CSHive,代码行数:18,代码来源:GZipHelper.cs

示例14: Compress

 /// <summary>
 /// 压缩二进制流
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] Compress(byte[] data)
 {
     using (var memoryStream = new MemoryStream())
     {
         using (var compressionStream = new GZipStream(memoryStream, CompressionMode.Compress))
         {
             compressionStream.Write(data, 0, data.Length);
             compressionStream.Flush();
         }
         //必须先关了compressionStream后才能取得正确的压缩流
         return memoryStream.ToArray();
     }
 }
开发者ID:CSStudio,项目名称:CSHive,代码行数:18,代码来源:GZipHelper.cs

示例15: StoredScript

 public StoredScript(String data, LighteningDataType dataType)
 {
     DataType = dataType;
     Uncompressed = Encoding.UTF8.GetBytes(data);
     using (MemoryStream result = new MemoryStream())
     {
         using (GZipStream gzStream = new GZipStream(result, CompressionLevel.Optimal, true))
         {
             gzStream.Write(Uncompressed, 0, Uncompressed.Length);
             gzStream.Flush();
         }
         Compressed = result.ToArray();
     }
 }
开发者ID:m3zercat,项目名称:Lightening.Memory,代码行数:14,代码来源:StoredScript.cs


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