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


C# DeflateStream.Close方法代码示例

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


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

示例1: Compress

 public static byte[] Compress(string data)
 {
     byte[] input = Encoding.ASCII.GetBytes(data);
       MemoryStream ms = new MemoryStream();
       DeflateStream zipper = new DeflateStream(ms, CompressionMode.Compress, true);
       zipper.Write(input, 0, input.Length);
       zipper.Close();
       byte[] output;
       if (ms.Length < input.Length)
       {
     output = new byte[ms.Length + 8];
     SetLength(input.Length, output, 0);
     SetLength((int)ms.Length, output, 4);
     ms.Position = 0;
     ms.Read(output, 8, output.Length - 8);
       }
       else
       {
     output = new byte[input.Length + 8];
     SetLength(input.Length, output, 0);
     SetLength(input.Length, output, 4);
     input.CopyTo(output, 8);
       }
       return output;
 }
开发者ID:VincentRisi,项目名称:jportal,代码行数:25,代码来源:Compression.cs

示例2: Compress

 /// <summary>
 /// 压缩
 /// </summary>
 /// <param name="inStream">输入流</param>
 /// <param name="outStream">输出流</param>
 public static void Compress(this Stream inStream, Stream outStream)
 {
     Stream stream = new DeflateStream(outStream, CompressionMode.Compress, true);
     CopyTo(inStream, stream);
     stream.Flush();
     stream.Close();
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:12,代码来源:IOHelper.cs

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

示例4: Compress

        public static byte[] Compress(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (var output = new MemoryStream())
            {
                // ZLib Header 0x78 0x9C
                output.WriteByte(0x78);
                output.WriteByte(0x9C);
                using (var input = new MemoryStream(data))
                {
                    using (var compressionStream = new DeflateStream(output, CompressionMode.Compress, true))
                    {
                        input.CopyTo(compressionStream);
                        compressionStream.Close();

                        // Adler32 hash of the uncompressed data
                        var adler32 = new Adler32();
                        adler32.Update(data);
                        byte[] hash = BitConverter.GetBytes((int) adler32.Value);
                        Array.Reverse(hash);
                        output.Write(hash, 0, hash.Length);
                        return output.ToArray();
                    }
                }
            }
        }
开发者ID:Translator5,项目名称:TuxLoL,代码行数:30,代码来源:ZLibHelper.cs

示例5: Decrypt

        public static StreamReader Decrypt(string source, int key)
        {
            byte[] data = System.Convert.FromBase64String(source);

            byte[] dec = AES.DecryptData(data, GetTrueKey(key), key.ToString() + "P8xvDLzPHvNiwVMkS3kPzQStAEDqdTMD", System.Security.Cryptography.PaddingMode.ISO10126);

            int d_len = System.BitConverter.ToInt32(dec, 40);

            MemoryStream ms = new MemoryStream(dec);
            ms.Position = 44;
            // Use the newly created memory stream for the compressed data.
            DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Decompress, true);
            //Console.WriteLine("Compression");
            byte[] zdec = new byte[d_len];
            int cnt = compressedzipStream.Read(zdec, 0, d_len);
            // Close the stream.
            compressedzipStream.Close();

            dec = new byte[cnt];
            System.Array.ConstrainedCopy(zdec, 0, dec, 0, cnt);

            MemoryStream mem_stream = new System.IO.MemoryStream(dec);
            StreamReader output = new System.IO.StreamReader((System.IO.Stream)mem_stream);

            return output;
        }
开发者ID:stephenZh,项目名称:l2net,代码行数:26,代码来源:Script_Crypt.cs

示例6: CompressTest

        public void CompressTest()
        {
            var s = "StartTime:13.4.201213:15:26;RunTime:00:01:24";

            var ms = new MemoryStream();
            var ds = new DeflateStream(ms, CompressionMode.Compress);

            var encoding = System.Text.Encoding.UTF8;
            var byteData = encoding.GetBytes(s);

            Trace.WriteLine("original    : {0}", s);
            ds.Write(byteData, 0, byteData.Length);
            ds.Close();
            byte[] compressed = ms.ToArray();

            Trace.WriteLine("compressed  : {0}", System.Convert.ToBase64String(compressed));

            ms = new MemoryStream(compressed);
            ds = new DeflateStream(ms, CompressionMode.Decompress);
            compressed = new byte[compressed.Length + 100];
            var offset = 0;

            while (true)
            {
                int bytesRead = ds.Read(compressed, offset, 1);
                if (bytesRead == 0) { break; }
                offset += bytesRead;
            }

            ds.Close();

            string uncompressed = encoding.GetString(compressed);

            Trace.WriteLine("uncompressed: {0}\n", uncompressed);
        }
开发者ID:ttu,项目名称:scratchpad,代码行数:35,代码来源:DataGetterTest.cs

示例7: GetEditorsTableFromResponse

        /// <summary>
        /// Get EditorsTable from server response.
        /// </summary>
        /// <param name="subResponse">The sub response from server.</param>
        /// <param name="site">Transfer ITestSite into this operation, for this operation to use ITestSite's function.</param>
        /// <returns>The instance of EditorsTable.</returns>
        public static EditorsTable GetEditorsTableFromResponse(FsshttpbResponse subResponse, ITestSite site)
        {
            if (subResponse == null || subResponse.DataElementPackage == null || subResponse.DataElementPackage.DataElements == null)
            {
                site.Assert.Fail("The parameter CellResponse is not valid, check whether the CellResponse::DataElementPackage or CellResponse::DataElementPackage::DataElements is null.");
            }

            foreach (DataElement de in subResponse.DataElementPackage.DataElements)
            {
                if (de.Data.GetType() == typeof(ObjectGroupDataElementData))
                {
                    ObjectGroupDataElementData ogde = de.Data as ObjectGroupDataElementData;

                    if (ogde.ObjectGroupData == null || ogde.ObjectGroupData.ObjectGroupObjectDataList.Count == 0)
                    {
                        continue;
                    }

                    for (int i = 0; i < ogde.ObjectGroupData.ObjectGroupObjectDataList.Count; i++)
                    {
                        if (IsEditorsTableHeader(ogde.ObjectGroupData.ObjectGroupObjectDataList[i].Data.Content.ToArray()))
                        {
                            string editorsTableXml = null;

                            // If the current object group object data is the header byte array 0x1a, 0x5a, 0x3a, 0x30, 0, 0, 0, 0, then the immediate following object group object data will contain the Editor table xml. 
                            byte[] buffer = ogde.ObjectGroupData.ObjectGroupObjectDataList[i + 1].Data.Content.ToArray();
                            System.IO.MemoryStream ms = null;
                            try
                            {
                                ms = new System.IO.MemoryStream();
                                ms.Write(buffer, 0, buffer.Length);
                                ms.Position = 0;
                                using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress))
                                {
                                    stream.Flush();
                                    byte[] decompressBuffer = new byte[buffer.Length * 3];
                                    stream.Read(decompressBuffer, 0, buffer.Length * 3);
                                    stream.Close();
                                    editorsTableXml = System.Text.Encoding.UTF8.GetString(decompressBuffer);
                                }

                                ms.Close();
                            }
                            finally
                            {
                                if (ms != null)
                                {
                                    ms.Dispose();
                                }
                            }

                            return GetEditorsTable(editorsTableXml);
                        }
                    }
                }
            }

            throw new InvalidOperationException("Cannot find any data group object data contain editor tables information.");
        }
开发者ID:OfficeDev,项目名称:Interop-TestSuites,代码行数:65,代码来源:EditorsTableUtils.cs

示例8: Deflate

 /// <summary>
 ///		Compresses a data buffer using a simple huffman deflate algorithem.
 /// </summary>
 /// <param name="data">Data buffer to compress.</param>
 /// <returns>Compressed version of data buffer.</returns>
 public static byte[] Deflate(byte[] data)
 {
     MemoryStream memoryStream = new MemoryStream();
     DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true);
     deflateStream.Write(data, 0, data.Length);
     deflateStream.Close();
     return memoryStream.ToArray();
 }
开发者ID:HampsterEater,项目名称:FusionGameEngine,代码行数:13,代码来源:Data+Methods.cs

示例9: Compress

 /// <summary>
 /// Compresses the specified input.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns>The compressed data.</returns>
 public static byte[] Compress(this byte[] input)
 {
     var inputStream = new MemoryStream(input);
     var outputStream = new MemoryStream();
     var compressor = new DeflateStream(outputStream, CompressionMode.Compress);
     inputStream.CopyTo(compressor);
     compressor.Close();
     return outputStream.ToArray();
 }
开发者ID:Celderon,项目名称:oxyplot,代码行数:14,代码来源:DeflateStreamExtensions.cs

示例10: Compress

 /// <summary>
 /// Compresses the specified data.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <returns></returns>
 public static byte[] Compress(byte[] data)
 {
     MemoryStream ms = new MemoryStream();
     DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress);
     ds.Write(data, 0, data.Length);
     ds.Flush();
     ds.Close();
     return ms.ToArray();
 }
开发者ID:Azerothian,项目名称:Empire,代码行数:14,代码来源:ByteArrays.cs

示例11: Decompress

 /// <summary>
 /// Decompresses the specified input.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns>The decompressed data.</returns>
 public static byte[] Decompress(this byte[] input)
 {
     var inflatedStream = new MemoryStream(input);
     var outputStream = new MemoryStream();
     var decompressor = new DeflateStream(inflatedStream, CompressionMode.Decompress);
     decompressor.CopyTo(outputStream);
     decompressor.Close();
     return outputStream.ToArray();
 }
开发者ID:Celderon,项目名称:oxyplot,代码行数:14,代码来源:DeflateStreamExtensions.cs

示例12: Decompress

 /// <summary>解压缩数据流</summary>
 /// <param name="inStream">输入流</param>
 /// <param name="outStream">输出流</param>
 public static void Decompress(this Stream inStream, Stream outStream)
 {
     // 第三个参数为true,保持数据流打开,内部不应该干涉外部,不要关闭外部的数据流
     using (Stream stream = new DeflateStream(inStream, CompressionMode.Decompress, true))
     {
         stream.CopyTo(outStream);
         stream.Close();
     }
 }
开发者ID:g992com,项目名称:esb,代码行数:12,代码来源:IOHelper.cs

示例13: Encode

 public byte[] Encode(byte[] data)
 {
     MemoryStream ms = new MemoryStream(data.Length);
     ms.WriteByte(0x78); // ZLib Header for compression level 3.
     ms.WriteByte(0x5e);
     DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress);
     ds.Write(data, 0, data.Length);
     ds.Close();
     return ms.ToArray();
 }
开发者ID:nholik,项目名称:Fo.Net,代码行数:10,代码来源:FlateFilter.cs

示例14: Compress

 public static byte[] Compress(byte[] data)
 {
     using (var compressedStream = new MemoryStream())
     using (var zipStream = new DeflateStream(compressedStream, CompressionMode.Compress))
     {
         zipStream.Write(data, 0, data.Length);
         zipStream.Close();
         return compressedStream.ToArray();
     }
 }
开发者ID:WoWServer,项目名称:WoWServer,代码行数:10,代码来源:ZLib.cs

示例15: Encode

 public byte[] Encode(byte[] data)
 {
     var output = new MemoryStream();
     var gzipstream = new DeflateStream(output, CompressionMode.Compress);
     gzipstream.Write(data, 0, data.Length);
     gzipstream.Close();
     byte[] compressed = output.ToArray();
     output.Close();
     return compressed;
 }
开发者ID:JacoRuit,项目名称:Lugubris,代码行数:10,代码来源:DeflateEncoder.cs


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