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


C# GZipStream.Close方法代码示例

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


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

示例1: backgroundWorker1DoWork

        void backgroundWorker1DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var movimentoBancarioService = ResolveComponent<IMovimentoBancarioService>();

                var infile = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var buffer = new byte[infile.Length];
                infile.Read(buffer, 0, buffer.Length);
                var ms = new MemoryStream();
                var compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
                compressedzipStream.Write(buffer, 0, buffer.Length);
                compressedzipStream.Close();

                _id = movimentoBancarioService.Importazione(ms.ToArray(), infile.Length);
                compressedzipStream.Close();
                compressedzipStream.Dispose();
            }
            catch (FileNotFoundException ex)
            {
                _log.ErrorFormat("Errore nell'importazione di un file CBI - FILE NON TROVATO - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Security.Login.Instance.CurrentLogin().Azienda);
                e.Result = string.Format("Il file '{0}' non è stato trovato", _fileName);
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore nell'importazione di un file CBI - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Security.Login.Instance.CurrentLogin().Azienda);                
                throw;
            }
        }
开发者ID:gipasoft,项目名称:Sfera,代码行数:29,代码来源:EsecuzioneImportazioneMovimentiUI.cs

示例2: CompressDataPackage

 /// <summary>
 /// Compresses an Epi Info 7 data package.
 /// </summary>
 /// <param name="fi">The file info for the raw data file that will be compressed.</param>
 public static void CompressDataPackage(FileInfo fi)
 {
     using (FileStream inFile = fi.OpenRead())
     {
         // Prevent compressing hidden and already compressed files.
         if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
                 != FileAttributes.Hidden & fi.Extension != ".gz")
         {
             using (FileStream outFile = File.Create(fi.FullName + ".gz"))
             {
                 using (GZipStream Compress = new GZipStream(outFile,
                         CompressionMode.Compress))
                 {
                     // Copy the source file into the compression stream.
                     byte[] buffer = new byte[4096];
                     int numRead;
                     while ((numRead = inFile.Read(buffer, 0, buffer.Length)) != 0)
                     {
                         Compress.Write(buffer, 0, numRead);
                     }
                     Compress.Close();
                     Compress.Dispose();
                 }
             }
         }
     }
 }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:31,代码来源:ImportExportHelper.cs

示例3: 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

示例4: Main

        static void Main(string[] args)
        {
            GZipStream gzOut = new GZipStream(File.Create(@"C:\Writing1mb.zip"), CompressionMode.Compress);
            DeflateStream dfOut = new DeflateStream(File.Create(@"C:\Writing1mb2.zip"), CompressionMode.Compress);
            TextWriter tw = new StreamWriter(gzOut);
            TextWriter tw2 = new StreamWriter(dfOut);

            try
            {
                for(int i = 0; i < 1000000; i++)
                {
                    tw.WriteLine("Writing until more than 1mb to ZIP it!");
                    tw2.WriteLine("Writing until more than 1mb to ZIP it!");
                }
            }
            catch(Exception)
            {

                throw;
            }
            finally
            {
                tw.Close();
                gzOut.Close();
                tw2.Close();
                dfOut.Close();
            }

        }
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:29,代码来源:Program.cs

示例5: Inflate

        public static byte[] Inflate(byte[] bytes)
        {
            MemoryStream ms = new MemoryStream(bytes);
            MemoryStream output = new MemoryStream();
            GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress);

            byte[] buffer = new byte[BUFFER_SIZE];
            try
            {
                while (gzip.CanRead)
                {
                    int bytesRead = gzip.Read(buffer, 0, buffer.Length);
                    if (bytesRead <= 0)
                        break;
                    output.Write(buffer, 0, bytesRead);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                gzip.Close();
                ms = null;
            }

            return output.ToArray();
        }
开发者ID:heksesang,项目名称:sharpotify,代码行数:28,代码来源:GZIP.cs

示例6: Decompress

        /// <summary>  
        /// decompress gzip data
        /// </summary>  
        /// <param name="data">compressed data</param>  
        /// <returns></returns>  
        public async static Task<byte[]> Decompress(byte[] data)
        {
            MemoryStream ms = null;
            GZipStream compressedzipStream = null;
            MemoryStream outBuffer = new MemoryStream();

            try
            {
                ms = new MemoryStream(data);
                compressedzipStream = new GZipStream(ms, CompressionMode.Decompress);

                byte[] block = new byte[1024 * 16];
                while (true)
                {
                    int bytesRead = await compressedzipStream.ReadAsync(block, 0, block.Length);
                    if (bytesRead <= 0)
                    {
                        break;
                    }
                    else
                    {
                        outBuffer.Write(block, 0, bytesRead);
                    }
                }
            }
            finally
            {
                if (null != compressedzipStream) compressedzipStream.Close();
                if (null != ms) ms.Close();
            }

            return outBuffer.ToArray();
        }
开发者ID:daoye,项目名称:baozouSpider,代码行数:38,代码来源:GZip.cs

示例7: CompressHandHistory

        public string CompressHandHistory(string fullHandText)
        {
            if (fullHandText == null) return null;

            //Transform string into byte[]
            byte[] byteArray = new byte[fullHandText.Length];
            int indexBA = 0;
            foreach (char item in fullHandText.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for compress
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Compress);

            //Compress
            sw.Write(byteArray, 0, byteArray.Length);
            //Close, DO NOT FLUSH cause bytes will go missing...
            sw.Close();

            //Transform byte[] zip data to string
            byteArray = ms.ToArray();
            System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
            foreach (byte item in byteArray)
            {
                sB.Append((char)item);
            }
            ms.Close();
            sw.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:koooee,项目名称:PokerHandHistoryParser,代码行数:34,代码来源:HandHistoryGZipCompressorImpl.cs

示例8: Decompress

        public byte[] Decompress(byte[] input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            var output = new List<byte>();

            using (var ms = new MemoryStream(input))
            {
                var gs = new GZipStream(ms, CompressionMode.Decompress);
                var readByte = gs.ReadByte();

                while (readByte != -1)
                {
                    output.Add((byte)readByte);
                    readByte = gs.ReadByte();
                }

                gs.Close();
                ms.Close();
            }

            return output.ToArray();
        }
开发者ID:himmelreich-it,项目名称:opencbs-online,代码行数:26,代码来源:GZipCompression.cs

示例9: UnzipObject

 public static object UnzipObject(IZEntity z)
 {
     object result = null;
     using (MemoryStream zipStream = new MemoryStream(z.Data))
     {
         zipStream.Position = 0;
         using (GZipStream gZipStream = new GZipStream(zipStream, CompressionMode.Decompress))
         {
             byte[] buffer = new byte[z.Size];
             gZipStream.Read(buffer, 0, z.Size);
             using (MemoryStream ms = new MemoryStream(buffer))
             {
                 BinaryFormatter bf = new BinaryFormatter();
                 ms.Position = 0;
                 result = bf.Deserialize(ms);
             }
             if (result.GetType() != z.Type)
             {
                 throw new InvalidCastException("Decompressed stream does not correspond to source type");
             }
             gZipStream.Close();
         }
         zipStream.Close();
     }
     return result;
 }
开发者ID:5509850,项目名称:baumax,代码行数:26,代码来源:ZLib.cs

示例10: Decompress

        public static byte[] Decompress(byte[] data)
        {
            try
            {
                MemoryStream input = new MemoryStream();
                input.Write(data, 0, data.Length);
                input.Position = 0;
                GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, true);
                MemoryStream output = new MemoryStream();
                byte[] buff = new byte[64];
                int read = -1;
                read = gzip.Read(buff, 0, buff.Length);
                while (read > 0)
                {
                    output.Write(buff, 0, read);
                    read = gzip.Read(buff, 0, buff.Length);
                }
                gzip.Close();
                return output.ToArray();
            }

            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "Decompress", "Compressor.cs");
                return null;
            }
        }
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:27,代码来源:Compressor.cs

示例11: Deserialize

 /// <summary>
 /// 反序列化 解压缩
 /// </summary>
 /// <param name="bytes"></param>
 /// <returns></returns>
 public static object Deserialize(byte[] bytes)
 {
     MemoryStream msNew = new MemoryStream(bytes);
     msNew.Position = 0;
     GZipStream gzipStream = new GZipStream(msNew, CompressionMode.Decompress);//创建解压对象
     byte[] buffer = new byte[4096];//定义数据缓冲
     int offset = 0;//定义读取位置
     MemoryStream ms = new MemoryStream();//定义内存流
     while ((offset = gzipStream.Read(buffer, 0, buffer.Length)) != 0)
     {
         ms.Write(buffer, 0, offset);//解压后的数据写入内存流
     }
     BinaryFormatter sfFormatter = new BinaryFormatter();//定义BinaryFormatter以反序列化object对象
     ms.Position = 0;//设置内存流的位置
     object obj;
     try
     {
         obj = (object)sfFormatter.Deserialize(ms);//反序列化
     }
     catch
     {
         throw;
     }
     finally
     {
         ms.Close();//关闭内存流
         ms.Dispose();//释放资源
     }
     gzipStream.Close();//关闭解压缩流
     gzipStream.Dispose();//释放资源
     msNew.Close();
     msNew.Dispose();
     return obj;
 }
开发者ID:JasonDevStudio,项目名称:SoaSolution,代码行数:39,代码来源:SerializerDeserialize.cs

示例12: Compress

        /// <summary>
        /// 对byte数组进行压缩
        /// </summary>
        /// <param name="data">待压缩的byte数组</param>
        /// <returns>压缩后的byte数组</returns>
        public static byte[] Compress(byte[] data)
        {
            try
            {
                byte[] buffer = null;
                using (MemoryStream ms = new MemoryStream())
                {
                    using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
                    {
                        zip.Write(data, 0, data.Length);
                        zip.Close();
                    }
                    buffer = new byte[ms.Length];
                    ms.Position = 0;
                    ms.Read(buffer, 0, buffer.Length);
                    ms.Close();
                }
                return buffer;

            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
开发者ID:notinmood,项目名称:hiland,代码行数:30,代码来源:CompressHelper.cs

示例13: CompressResponse

        private Response CompressResponse(Request request, Response response)
        {
            if (!response.ContentType.Contains("image")
                && request.Headers.AcceptEncoding.Any(x => x.Contains("gzip"))
                && (!response.Headers.ContainsKey("Content-Encoding") || response.Headers["Content-Encoding"] != "gzip"))
            {
                var data = new MemoryStream();
                response.Contents.Invoke(data);
                data.Position = 0;
                if (data.Length < 1024)
                {
                    response.Contents = stream =>
                    {
                        data.CopyTo(stream);
                        stream.Flush();
                    };
                }
                else
                {
                    response.Headers["Content-Encoding"] = "gzip";
                    response.Contents = s =>
                    {
                        var gzip = new GZipStream(s, CompressionMode.Compress, true);
                        data.CopyTo(gzip);
                        gzip.Close();
                    };
                }
            }

            return response;
        }
开发者ID:Kiljoymccoy,项目名称:NzbDrone,代码行数:31,代码来源:GZipPipeline.cs

示例14: 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

示例15: FileCompress

        public void FileCompress(string sourceFile, string destinationFile)
        {
            // ----- Decompress a previously compressed string.
            //       First, create the input file stream.
            FileStream sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read);

            // ----- Create the output file stream.
            FileStream destinationStream = new FileStream(destinationFile, FileMode.Create, FileAccess.Write);

            // ----- Bytes will be processed by a compression
            //       stream.
            GZipStream compressedStream = new GZipStream(destinationStream, CompressionMode.Compress, true);

            // ----- Process bytes from one file into the other.
            const int BlockSize = 4096;
            byte[] buffer = new byte[BlockSize + 1];
            int bytesRead = default(int);
            do
            {
                bytesRead = sourceStream.Read(buffer, 0, BlockSize);
                if (bytesRead == 0)
                {
                    break;
                }
                compressedStream.Write(buffer, 0, bytesRead);
            } while (true);

            // ----- Close all the streams.
            sourceStream.Close();
            compressedStream.Close();
            destinationStream.Close();
        }
开发者ID:versidyne,项目名称:cresco,代码行数:32,代码来源:Compress.cs


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