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


C# GZipStream.Read方法代码示例

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


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

示例1: Decompress

        /// <summary>
        /// Decompresses the file at the given path. Returns the path of the
        /// decompressed file.
        /// </summary>
        /// <param name="path">The path to decompress.</param>
        /// <returns>The path of the decompressed file.</returns>
        public string Decompress(string path)
        {
            string outputPath = Regex.Replace(path, @"\.gz$", String.Empty, RegexOptions.IgnoreCase);

            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            using (FileStream fs = File.OpenRead(path))
            {
                using (FileStream output = File.Create(outputPath))
                {
                    using (GZipStream gzip = new GZipStream(fs, CompressionMode.Decompress))
                    {
                        byte[] buffer = new byte[4096];
                        int count = 0;

                        while (0 < (count = gzip.Read(buffer, 0, buffer.Length)))
                        {
                            output.Write(buffer, 0, count);
                        }
                    }
                }
            }

            return outputPath;
        }
开发者ID:ChadBurggraf,项目名称:sthreeql,代码行数:34,代码来源:GZipCompressor.cs

示例2: Decompress

        public static void Decompress(byte[] data, string path)
        {
            byte[] buffer = new byte[BufferSize];
            int read;

            using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write))
            using (GZipStream gzip = new GZipStream(new MemoryStream(data), CompressionMode.Decompress, CompressionLevel.BestCompression, false))
            {
                while ((read = gzip.Read(buffer, 0, BufferSize)) > 0)
                {
                    output.Write(buffer, 0, read);
                    output.Flush();
                }
            }
        }
开发者ID:Ravenheart,项目名称:driversolutions,代码行数:15,代码来源:Tools.cs

示例3: uncompress

        static public byte[] uncompress(byte[] bytes)
        {

            byte[] working = new byte[1024 * 20];
            var input = new MemoryStream(bytes);
            var output = new MemoryStream();
            using (Stream decompressor = new GZipStream(input, CompressionMode.Decompress, true))
            {

                int n;
                while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                {
                    output.Write(working, 0, n);
                }

            }
            return output.ToArray();

        }
开发者ID:superkaka,项目名称:LibForUnity,代码行数:19,代码来源:GZipCompresser.cs

示例4: getUnzippedPath

    private static string getUnzippedPath(string gzipPath_)
    {
      var csvPath = gzipPath_.Replace(".gz", string.Empty);

      if (File.Exists(csvPath)) return csvPath;

      var buffer = new byte[2048];
      int n = 1;

      try
      {
        if (!File.Exists(csvPath))
        {
          using (var input = File.OpenRead(gzipPath_))
          {
            using (var decompressor = new GZipStream(input, CompressionMode.Decompress, true))
            {
              using (var output = File.Create(csvPath))
              {
                do
                {
                  n = decompressor.Read(buffer, 0, buffer.Length);
                  if (n > 0) output.Write(buffer, 0, n);
                }
                while (n > 0);
              }
            }
          }
        }
      }
      catch (Exception ex_)
      {
        Logger.Error(string.Format("Error processing file {0}. error: {1}{2}", gzipPath_, ex_.Message, ex_.StackTrace), typeof(FileHelper));
      }

      return csvPath;
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:37,代码来源:FileHelper.cs

示例5: Decompress

 /// <summary>
 /// Decompresses a byte array using the specified compression type.
 /// </summary>
 /// <param name="bytes">The byte array to be decompressed.</param>
 /// <param name="type">Type of compression to use.</param>
 /// <returns>Decompressed byte array.</returns>
 public static byte[] Decompress(this byte[] bytes, CompressionType type)
 {
     int size = 4096;
     byte[] buffer = new byte[size];
     using (MemoryStream memory = new MemoryStream())
     {
         using (MemoryStream memory2 = new MemoryStream(bytes))
             switch (type)
             {
                 case CompressionType.Zlib:
                     using (ZlibStream stream = new ZlibStream(memory2, CompressionMode.Decompress))
                     {
                         int count = 0;
                         while ((count = stream.Read(buffer, 0, size)) > 0)
                             memory.Write(buffer, 0, count);
                     }
                     break;
                 case CompressionType.GZip:
                     using (GZipStream stream = new GZipStream(memory2, CompressionMode.Decompress))
                     {
                         int count = 0;
                         while ((count = stream.Read(buffer, 0, size)) > 0)
                             memory.Write(buffer, 0, count);
                     }
                     break;
                 default:
                     throw new ArgumentException("Unknown compression type.");
             }
         return memory.ToArray();
     }
 }
开发者ID:Shade2010,项目名称:ForgeCraft,代码行数:37,代码来源:Extensions.cs

示例6: Post

        private IEnumerator Post(WWW www, Action<string> wwwSuccessCallback, Action<string> wwwErrorCallback)
        {
            yield return www;
            if (!string.IsNullOrEmpty(www.error))
            {
                wwwErrorCallback(www.error);
            }
            else
            {
#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
                if (PlayFabSettings.CompressApiData)
                {
                    try
                    {
                        var stream = new MemoryStream(www.bytes);
                        using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress, false))
                        {
                            var buffer = new byte[4096];
                            using (var output = new MemoryStream())
                            {
                                int read;
                                while ((read = gZipStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    output.Write(buffer, 0, read);
                                }
                                output.Seek(0, SeekOrigin.Begin);
                                var streamReader = new System.IO.StreamReader(output);
                                var jsonResponse = streamReader.ReadToEnd();
                                //Debug.Log(jsonResponse);
                                wwwSuccessCallback(jsonResponse);
                            }
                        }
                    }
                    catch
                    {
                        //if this was not a valid GZip response, then send the message back as text to the call back.
                        wwwSuccessCallback(www.text);
                    }
                }
                else
                {
#endif
                    wwwSuccessCallback(www.text);
#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
                }
#endif
            }
        }
开发者ID:codermoon,项目名称:RetroRun,代码行数:48,代码来源:PlayFabWWW.cs

示例7: Gunzip

        /// <summary>
        /// Gunzips the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string Gunzip(this byte[] input) {
            var bytes = new List<byte>();
            using (var gzStr = new GZipStream(new MemoryStream(input), CompressionMode.Decompress)) {
                var bytesRead = new byte[512];
                while (true) {
                    var numRead = gzStr.Read(bytesRead, 0, 512);
                    if (numRead > 0) {
                        bytes.AddRange(bytesRead.Take(numRead));
                    }
                    else {
                        break;
                    }
                }
            }

            return bytes.ToArray().ToUtf8String();
        }
开发者ID:segilbert,项目名称:coapp,代码行数:23,代码来源:StringExtensions.cs

示例8: Unzip

        protected void Unzip()
        {
            using (MemoryStream i = new MemoryStream(bytes)) {
            // Verify gzip header.
            byte[] header = new byte[10];
            if (i.Read(header, 0, header.Length) == 10 && header[0] == 0x1F && header[1] == 0x8B && header[2] == 8) {
              // Back to start.
              i.Seek(0, SeekOrigin.Begin);

              using (MemoryStream o = new MemoryStream()) {
            using (GZipStream gzip = new GZipStream(i, CompressionMode.Decompress)) {
              var buffer = new byte[1024];

              do {
                int read = gzip.Read(buffer, 0, buffer.Length);

                if (read == 0) {
                  break;
                }

                o.Write(buffer, 0, read);
              } while (true);
            }

            this.bytes = o.ToArray();
              }
            }
              }
        }
开发者ID:notrubp,项目名称:Platformer,代码行数:29,代码来源:HttpResponse.cs

示例9: Post

        private IEnumerator Post(WWW www, Action<string> wwwSuccessCallback, Action<string> wwwErrorCallback)
        {
            yield return www;
            if (!string.IsNullOrEmpty(www.error))
            {
                wwwErrorCallback(www.error);
            }
            else
            {
                try
                {
#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
                    string encoding;
                    if (www.responseHeaders.TryGetValue("Content-Encoding", out encoding) && encoding.ToLower() == "gzip")
                    {
                        var stream = new MemoryStream(www.bytes);
                        using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress, false))
                        {
                            var buffer = new byte[4096];
                            using (var output = new MemoryStream())
                            {
                                int read;
                                while ((read = gZipStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    output.Write(buffer, 0, read);
                                }
                                output.Seek(0, SeekOrigin.Begin);
                                var streamReader = new System.IO.StreamReader(output);
                                var jsonResponse = streamReader.ReadToEnd();
                                //Debug.Log(jsonResponse);
                                wwwSuccessCallback(jsonResponse);
                            }
                        }
                    }
                    else
#endif
                    {
                        wwwSuccessCallback(www.text);
                    }
                }
                catch (Exception e)
                {
                    wwwErrorCallback("Unhandled error in PlayFabWWW: " + e);
                }
            }
        }
开发者ID:PlayFab,项目名称:PlayFab-Samples,代码行数:46,代码来源:PlayFabWWW.cs

示例10: UnpackDirectory

    public static void UnpackDirectory(string sourcePath_, string unpackToThisDirectory_, string processedDirectory_, string errorDirectory_, string noMetaDirectory_,  bool recurse_, bool processFile_=true)
    {
      if (!Directory.Exists(sourcePath_))
        return;

      foreach(var zipPath in Directory.GetFiles(sourcePath_,"*.gz"))
      {
        var fileName = new FileInfo(zipPath).Name;
        var csvFileName = fileName.Replace(".gz", string.Empty);

        var unpackPath = string.Format(@"{0}\{1}", unpackToThisDirectory_, csvFileName);

        var buffer = new byte[2048];
        int n=1;
        Logger.Debug(string.Format("Unpacking {0}", new FileInfo(fileName).Name), typeof(FuturesIntradaySaver));

        try
        {
          if (!File.Exists(unpackPath))
          {
            using (var input = File.OpenRead(zipPath))
            {
              using (var decompressor = new GZipStream(input, CompressionMode.Decompress, true))
              {
                using (var output = File.Create(unpackPath))
                {
                  do
                  {
                    n = decompressor.Read(buffer, 0, buffer.Length);
                    if (n > 0) output.Write(buffer, 0, n);
                  }
                  while (n > 0);
                }
              }
            }
          }

          if(processFile_)
            processFile(unpackPath, processedDirectory_, errorDirectory_, noMetaDirectory_);
        }
        catch (Exception ex_)
        {
          Logger.Error( string.Format("Error processing file {0}. error: {1}{2}", fileName, ex_.Message, ex_.StackTrace),typeof(FuturesIntradaySaver));

          string errorPath = string.Format(@"{0}\{1}", errorDirectory_, csvFileName);

          if (processFile_ && File.Exists(unpackPath)) File.Move(unpackPath, errorPath);
        }
      }

      if(recurse_)
        foreach (var dir in Directory.GetDirectories(sourcePath_))
          UnpackDirectory(dir, unpackToThisDirectory_, processedDirectory_, errorDirectory_, noMetaDirectory_, recurse_,
            processFile_);
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:55,代码来源:FuturesIntradaySaver.cs

示例11: Load

        public void Load(Config config, byte[] data)
        {
			MemoryStream memoryStream = new MemoryStream(data);
			
            BinaryReader br = new BinaryReader(memoryStream);
			
            //Read version info
            string version = br.ReadString();
            if (version != VERSION_INFO)
                return;
			
			//Read compressed bytes
			int uncompressedSize = br.ReadInt32();
			
			//Uncompress bytes
			byte[] uncompressedBytes = new byte[uncompressedSize];
			GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress);
			int bytesRead = 0;
			
			while(true)
			{
				int read = gzipStream.Read(uncompressedBytes, bytesRead, uncompressedSize - bytesRead);
				
				if (read == 0)
					break;
				
				bytesRead += read;
			}
			
			br = new BinaryReader(new MemoryStream(uncompressedBytes));

			//Load world from uncompressed bytes
            Load(br, false);
			
            tileManager.Create(config.tileDefinitions, sizeXbits, sizeYbits, sizeZbits);
            itemManager.Create(config.itemDefinitions);
            avatarManager.Create(config.avatarDefinitions);
            sectorManager.Create();
            dayCycleManager.Create(config.dayInfo);

            tileManager.Load(br);
            itemManager.Load(br);
            avatarManager.Load(br);
            sectorManager.Load(br);
            dayCycleManager.Load(br);

            gameplay.WorldLoaded();
        }
开发者ID:carriercomm,项目名称:CubeWorld,代码行数:48,代码来源:CubeWorld.cs

示例12: LoadMultiplayer

        public MultiplayerConfig LoadMultiplayer(byte[] data)
        {
            MemoryStream memoryStream = new MemoryStream(data);
            BinaryReader br = new BinaryReader(memoryStream);

            //Read compressed bytes
            int uncompressedSize = br.ReadInt32();

            //Uncompress bytes
            byte[] uncompressedBytes = new byte[uncompressedSize];
            GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress);
            int bytesRead = 0;

            while (true)
            {
                int read = gzipStream.Read(uncompressedBytes, bytesRead, uncompressedSize - bytesRead);

                if (read == 0)
                    break;

                bytesRead += read;
            }

            br = new BinaryReader(new MemoryStream(uncompressedBytes));

            //Load world from uncompressed bytes
            MultiplayerConfig config = LoadMultiplayer(br);

            tileManager.Create(config.tileDefinitions, sizeXbits, sizeYbits, sizeZbits);
            itemManager.Create(config.itemDefinitions);
            avatarManager.Create(config.avatarDefinitions);
            sectorManager.Create();
            dayCycleManager.Create(null);

            tileManager.Load(br);
            itemManager.Load(br);
            sectorManager.Load(br);
            dayCycleManager.Load(br);

            //Player avatar
            int playerObjectId = br.ReadInt32();
            Player player = (Player) avatarManager.CreateAvatar(avatarManager.GetAvatarDefinitionById("player"), playerObjectId, new Vector3(), false);
            player.Load(br);

            cwListener.CreateObject(player);

            gameplay.WorldLoaded();

            return config;
        }
开发者ID:carriercomm,项目名称:CubeWorld,代码行数:50,代码来源:CubeWorld.cs


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