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


C# GZipStream.Read方法代码示例

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


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

示例1: Decompress

 public byte[] Decompress(MemoryStream input)
 {
     try
     {
         using (var output = new MemoryStream())
         {
             using (var gzip = new GZipStream(input, CompressionMode.Decompress, true))
             {
                 var buff = new byte[64];
                 int 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)
     {
         throw new Exception("Cannot Decompress Session Data", ex);
     }
 }
开发者ID:evereq,项目名称:couchbase-aspnet,代码行数:25,代码来源:GzipCompressor.cs

示例2: Decompress

        public static byte[] Decompress(byte[] data)
        {
            GZipStream gZipStream;
            using (MemoryStream inputMemoryStream = new MemoryStream())
            {
                inputMemoryStream.Write(data, 0, data.Length);
                inputMemoryStream.Position = 0;

                CompressionMode compressionMode = CompressionMode.Decompress;
                gZipStream = new GZipStream(inputMemoryStream, compressionMode, true);

                using (MemoryStream outputMemoryStream = new MemoryStream())
                {
                    byte[] buffer = new byte[1024];
                    int byteRead = -1;
                    byteRead = gZipStream.Read(buffer, 0, buffer.Length);

                    while (byteRead > 0)
                    {
                        outputMemoryStream.Write(buffer, 0, byteRead);
                        byteRead = gZipStream.Read(buffer, 0, buffer.Length);
                    }

                    gZipStream.Close();
                    return outputMemoryStream.ToArray();
                }
            }
        }
开发者ID:jsonsugar,项目名称:GebCommon,代码行数:28,代码来源:Compress.cs

示例3: DisplayContent

 private static void DisplayContent(HttpWebResponse response, string id)
 {
     Stream stream = response.GetResponseStream();
     if (stream != null)
     {
         string filePath = "D:\\pic\\" + id + ".png";
         FileStream fs = new FileStream(filePath, FileMode.Create);
         GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress);
         byte[] bytes = new byte[1024];
         int len;
         if ((len = gzip.Read(bytes, 0, bytes.Length)) > 0)
         {
             fs.Write(bytes, 0, len);
         }
         else
         {
             fs.Close();
             File.Delete(filePath);
             throw new Exception();
         }
         while ((len = gzip.Read(bytes, 0, bytes.Length)) > 0)
         {
             fs.Write(bytes, 0, len);
         }
         fs.Close();
     }
 }
开发者ID:HaleLu,项目名称:GetPic,代码行数:27,代码来源:Form1.cs

示例4: DecompressData

        public static byte[] DecompressData(byte[] data)
        {
            MemoryStream input = new MemoryStream();
            input.Write(data, 0, data.Length);
            input.Position = 0;
            MemoryStream output;
            using (GZipStream gZipStream = new GZipStream(input, CompressionMode.Decompress, true))
            {
                output = new MemoryStream();
                byte[] buff = new byte[64];
                int read = -1;

                read = gZipStream.Read(buff, 0, buff.Length);
                while (read > 0)
                {
                    output.Write(buff, 0, read);
                    read = gZipStream.Read(buff, 0, buff.Length);
                }
                gZipStream.Close();
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            return output.ToArray();
        }
开发者ID:sarang25491,项目名称:TwitNet,代码行数:25,代码来源:GZip.cs

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

示例6: GZipDecompress

        /// <summary>
        ///     The GZIP decompress.
        /// </summary>
        /// <param name="data">The data to decompress.</param>
        /// <returns>The decompressed data</returns>
        public static byte[] GZipDecompress(this byte[] data)
        {
            byte[] bytes = null;

            if (data != null)
            {
                using (var input = new MemoryStream(data.Length))
                {
                    input.Write(data, 0, data.Length);
                    input.Position = 0;

                    var gzip = new GZipStream(input, CompressionMode.Decompress);

                    using (var output = new MemoryStream(data.Length))
                    {
                        var buff = new byte[64];
                        int read = gzip.Read(buff, 0, buff.Length);

                        while (read > 0)
                        {
                            output.Write(buff, 0, buff.Length);
                            read = gzip.Read(buff, 0, buff.Length);
                        }

                        bytes = output.ToArray();
                    }
                }
            }

            return bytes;
        }
开发者ID:MGramolini,项目名称:vodca,代码行数:36,代码来源:Extensions.Compression.GZip.cs

示例7: Decompress

        /// <summary>
        /// Decompresses an array of bytes.
        /// </summary>
        /// <param name="bytes">The array of bytes to decompress.</param>
        /// <returns>The decompressed array of bytes.</returns>
        public static byte[] Decompress(this byte[] bytes)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;

                using (GZipStream compressedStream = new GZipStream(stream, CompressionMode.Decompress, true))
                {
                    using (MemoryStream output = new MemoryStream())
                    {
                        byte[] buffer = new byte[32*1024];
                        int count = compressedStream.Read(buffer, 0, buffer.Length);
                        while (count > 0)
                        {
                            output.Write(buffer, 0, count);
                            count = compressedStream.Read(buffer, 0, buffer.Length);
                        }

                        compressedStream.Close();
                        return output.ToArray();
                    }
                }
            }
        }
开发者ID:petervyvey,项目名称:membrane,代码行数:30,代码来源:CompressionExtension.cs

示例8: btnOK_Click

 private void btnOK_Click(object sender, EventArgs e)
 {
     WaitCallback callBack = null;
     if (this.gvReplays.GetSelectedRows().Length > 0)
     {
         ReplayInfo row = this.gvReplays.GetRow(this.gvReplays.GetSelectedRows()[0]) as ReplayInfo;
         base.Enabled = false;
         if (callBack == null)
         {
             callBack = delegate (object o) {
                 try
                 {
                     ReplayInfo info = (o as object[])[0] as ReplayInfo;
                     if (info != null)
                     {
                         string address = ConfigSettings.GetString("BaseReplayURL", "http://gpgnet.gaspowered.com/replays/") + info.Location;
                         WebClient client = new WebClient();
                         string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Gas Powered Games\SupremeCommander\replays\" + User.Current.Name;
                         if (!Directory.Exists(path))
                         {
                             Directory.CreateDirectory(path);
                         }
                         path = path + @"\" + info.Location.Replace("/", ".");
                         if (!System.IO.File.Exists(path))
                         {
                             client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.client_DownloadProgressChanged);
                             client.DownloadFile(address, path + ".gzip");
                             FileStream stream = new FileStream(path + ".gzip", FileMode.Open);
                             FileStream stream2 = new FileStream(path, FileMode.Create);
                             GZipStream stream3 = new GZipStream(stream, CompressionMode.Decompress);
                             byte[] buffer = new byte[0x100];
                             for (int j = stream3.Read(buffer, 0, 0x100); j > 0; j = stream3.Read(buffer, 0, 0x100))
                             {
                                 stream2.Write(buffer, 0, j);
                             }
                             stream3.Close();
                             stream.Close();
                             stream2.Close();
                         }
                         if (System.IO.File.Exists(path))
                         {
                             Process.Start(path);
                         }
                     }
                 }
                 catch (Exception exception)
                 {
                     ErrorLog.WriteLine(exception);
                 }
                 base.BeginInvoke((VGen0)delegate {
                     base.Close();
                 });
             };
         }
         ThreadQueue.QueueUserWorkItem(callBack, new object[] { row });
     }
 }
开发者ID:micheljung,项目名称:gpgnetfix,代码行数:57,代码来源:DlgReplayList.cs

示例9: Blockchange2

        public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            p.SendBlockchange(x, y, z, p.level.GetTile(x, y, z));
            CatchPos cpos = (CatchPos)p.blockchangeObject;
            FileStream fs = File.OpenRead(@Server.backupLocation + "/" + p.level.name + "/" + cpos.backup + "/" + p.level.name + ".lvl");
            GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
            byte[] ver = new byte[2];
            gs.Read(ver, 0, ver.Length);
            ushort version = BitConverter.ToUInt16(ver, 0);
            ushort[] vars = new ushort[6];
            try
            {
                if (version == 1874)
                {
                    byte[] header = new byte[16]; gs.Read(header, 0, header.Length);

                    vars[0] = BitConverter.ToUInt16(header, 0);
                    vars[1] = BitConverter.ToUInt16(header, 2);
                    vars[2] = BitConverter.ToUInt16(header, 4);
                }
                else
                {
                    byte[] header = new byte[12]; gs.Read(header, 0, header.Length);

                    vars[0] = version;
                    vars[1] = BitConverter.ToUInt16(header, 0);
                    vars[2] = BitConverter.ToUInt16(header, 2);
                }
                byte[] blocks = new byte[vars[0] * vars[2] * vars[1]];
                gs.Read(blocks, 0, blocks.Length);
                gs.Dispose();
                fs.Dispose();

                if (blocks.Length != p.level.blocks.Length) { p.SendMessage("Cant restore selection of different size maps."); blocks = null; return; }

                if (p.level.bufferblocks && !p.level.Instant)
                {
                    for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                        for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                            for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                                BlockQueue.Addblock(p, xx, yy, zz, blocks[xx + (zz * vars[0]) + (yy * vars[0] * vars[1])]);
                }
                else
                {
                    for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                        for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                            for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                                p.level.Blockchange(p, xx, yy, zz, blocks[xx + (zz * vars[0]) + (yy * vars[0] * vars[1])]);
                }

                blocks = null;
                if (p.staticCommands) p.Blockchange += Blockchange1;
            }
            catch { Server.s.Log("Restore selection failed"); }
        }
开发者ID:AnthonyANI,项目名称:MCForge-MCLawl,代码行数:56,代码来源:CmdRestoreSelection.cs

示例10: OnUriResponse

 private static void OnUriResponse(Uri uri, BinaryReader reader)
 {
     using (var stream = new GZipStream(reader.BaseStream, CompressionMode.Decompress))
     {
         const int size = 1024;
         var buffer = new byte[size];
         var numBytes = stream.Read(buffer, 0, size);
         while (numBytes > 0)
         {
             Console.Write(Encoding.UTF8.GetString(buffer, 0, numBytes));
             numBytes = stream.Read(buffer, 0, size);
         }
     }
 }
开发者ID:simonlongson,项目名称:tx.link.incoming,代码行数:14,代码来源:HistoricMarketDataRequester.cs

示例11: Load

        public Level Load(string levelName, string path)
        {
            Level finalLevel = new Level(new Vector3S(32, 32, 32));
            finalLevel.Name = levelName;
            using (FileStream fs = File.OpenRead(path)) {
                using (GZipStream gs = new GZipStream(fs, CompressionMode.Decompress)) {
                    byte[] ver = new byte[2];
                    gs.Read(ver, 0, ver.Length);
                    ushort version = BitConverter.ToUInt16(ver, 0);

                    //if (version != 1874) //Is a old MCForge level!
                    //    throw new Exception(path + " is not a valid MCForge Level");
                    // Older levels WILL STILL WORK WITH THIS so you don't need this check. .dat files won't load though.

                    ushort[] vars = new ushort[6];
                    byte[] rot = new byte[2];
                    byte[] header = new byte[16];

                    gs.Read(header, 0, header.Length);

                    vars[0] = BitConverter.ToUInt16(header, 0); //X
                    vars[1] = BitConverter.ToUInt16(header, 2); //Z
                    vars[2] = BitConverter.ToUInt16(header, 4); //Y
                    vars[3] = BitConverter.ToUInt16(header, 6); //SpawnX
                    vars[4] = BitConverter.ToUInt16(header, 8); //SpawnZ
                    vars[5] = BitConverter.ToUInt16(header, 10); //SpawnY

                    rot[0] = header[12]; //SpawnHeading
                    rot[1] = header[13]; //SpawnYaw

                    finalLevel.CWMap.Size = new Vector3S((short)vars[0], (short)vars[1], (short)vars[2]);
                    finalLevel.CWMap.SpawnPos = new Vector3S((short)vars[3], (short)vars[4], (short)vars[5]);
                    finalLevel.CWMap.SpawnRotation = new Vector2S(rot[0], rot[1]);
                    finalLevel.TotalBlocks = finalLevel.CWMap.Size.x * finalLevel.CWMap.Size.z * finalLevel.CWMap.Size.y;

                    byte[] blocks = new byte[finalLevel.CWMap.Size.x * finalLevel.CWMap.Size.z * finalLevel.CWMap.Size.y];
                    gs.Read(blocks, 0, blocks.Length);
                    finalLevel.CWMap.BlockData = new byte[finalLevel.TotalBlocks];
                    for (int x = 0; x < finalLevel.CWMap.Size.x; x++)
                        for (int y = 0; y < finalLevel.CWMap.Size.y; y++)
                            for (int z = 0; z < finalLevel.CWMap.Size.z; z++)
                                finalLevel.SetBlock(x, z, y, (byte)OldMCForgeToNewMCForge.Convert(blocks[finalLevel.PosToInt((ushort)x, (ushort)z, (ushort)y)]));  //Converts all custom blocks to normal blocks.

                }
            }
            finalLevel.HandleMetaData();
            Logger.Log("[Level] " + levelName + " was loaded");
            return finalLevel;
        }
开发者ID:headdetect,项目名称:MCForge6-Vanilla,代码行数:49,代码来源:MCForgeOldMap.cs

示例12: AssembleFiles

 private static void AssembleFiles(List<string> files, string destination)
 {
     for (int i = 0; i < files.Count; i++)
     {
         var fsRead = new FileStream(files[i], FileMode.Open);
         var fsWrite = new FileStream(destination, FileMode.Append);
         byte[] buffer = new byte[4096];
         using (fsRead)
         {
             using (fsWrite)
             {
                 using (var deCompress = new GZipStream(fsRead,CompressionMode.Decompress,false))
                 {
                     while (true)
                     {
                         int readBytes = deCompress.Read(buffer, 0, buffer.Length);
                         if (readBytes == 0)
                         {
                             break;
                         }
                         fsWrite.Write(buffer, 0, buffer.Length);
                     }
                 }
             }
         }
     }
 }
开发者ID:Effektus,项目名称:FilesAndStreams,代码行数:27,代码来源:zipSliced.cs

示例13: Memory_Compress_Decompress

        public void Memory_Compress_Decompress() {
            var input = (byte[])PlainBytes.Clone();
            byte[] compressed;

            using(var outStream = new MemoryStream(input.Length)) {
                using(var gzip = new GZipStream(outStream, CompressionMode.Compress)) {
                    gzip.Write(input, 0, input.Length);
                }
                compressed = outStream.ToArray();
                Assert.IsNotNull(compressed);
                Assert.IsTrue(compressed.Length > 0);
            }

            using(var outStream = new MemoryStream(input.Length))
            using(var gzip = new GZipStream(new MemoryStream(compressed), CompressionMode.Decompress)) {
                var readCount = 0;
                var buffer = new byte[CompressorTool.BUFFER_SIZE];

                while((readCount = gzip.Read(buffer, 0, buffer.Length)) > 0) {
                    outStream.Write(buffer, 0, readCount);
                }

                byte[] decompressed = outStream.ToArray();

                Assert.IsTrue(decompressed.Length > 0);
                Assert.AreEqual(PlainBytes, decompressed);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:28,代码来源:AsyncCompressorFixture.cs

示例14: GZipUncompress

        public Byte[] GZipUncompress(Byte[] buffer)
        {
            using (MemoryStream _mStream = new MemoryStream(buffer))
            {
                using (GZipStream _gzip = new GZipStream(_mStream, CompressionMode.Decompress))
                {
                    const int _size = 4096;
                    byte[] _buffer = new byte[_size];

                    using (MemoryStream _oStream = new MemoryStream())
                    {
                        int _count = 0;

                        do
                        {
                            _count = _gzip.Read(_buffer, 0, _size);
                            if (_count > 0)
                            {
                                _oStream.Write(_buffer, 0, _count);
                            }
                        } while (_count > 0);

                        return _oStream.ToArray();
                    }
                }
            }
        }
开发者ID:txstudio,项目名称:txstudio.Owin.GZipMiddleware,代码行数:27,代码来源:GZipMiddleware.cs

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


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