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


C# GZipInputStream.Read方法代码示例

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


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

示例1: Decompress

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

                using (Stream decompressStream = new GZipInputStream(inputStream))
                {
                    using (MemoryStream outputStream = new MemoryStream())
                    {
                        byte[] buffer = new byte[BUFFER_SIZE];
                        while (true)
                        {
                            int size = decompressStream.Read(buffer, 0, buffer.Length);
                            if (size > 0)
                            {
                                outputStream.Write(buffer, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        decompressStream.Close();
                        return outputStream.ToArray();
                    }
                }
            }
        }
开发者ID:danni95,项目名称:Core,代码行数:30,代码来源:SharpCompressionProvider.cs

示例2: GetDecompressedBytes

        public static byte[] GetDecompressedBytes(this WWW www)
        {
            #if UNITY_STANDALONE_WIN || UNITY_WEBGL
            string contentEncoding;
            if (www.responseHeaders == null ||
                !www.responseHeaders.TryGetValue(ContentEncodingHeaderName, out contentEncoding) ||
                !contentEncoding.Equals(GzipContentEncodingValue, StringComparison.OrdinalIgnoreCase))
            {
                return www.bytes;
            }

            byte[] buffer = new byte[4096];
            using (var stream = new MemoryStream(www.bytes))
            using (var gzip = new GZipInputStream(stream))
            using (var outMs = new MemoryStream(www.bytes.Length))
            {
                int bytesRead = 0;
                while ((bytesRead = gzip.Read(buffer, 0, buffer.Length)) > 0)
                {
                    outMs.Write(buffer,0, bytesRead);
                }
                return outMs.ToArray();
            }

            #else
            return www.bytes;
            #endif
        }
开发者ID:urgamedev,项目名称:RenderCubes,代码行数:28,代码来源:WWWExtensions.cs

示例3: TestGZip

        public void TestGZip()
        {
            MemoryStream ms = new MemoryStream();
            GZipOutputStream outStream = new GZipOutputStream(ms);

            byte[] buf = new byte[100000];
            System.Random rnd = new Random();
            rnd.NextBytes(buf);

            outStream.Write(buf, 0, buf.Length);
            outStream.Flush();
            outStream.Finish();

            ms.Seek(0, SeekOrigin.Begin);

            GZipInputStream inStream = new GZipInputStream(ms);
            byte[] buf2 = new byte[buf.Length];
            int    pos  = 0;
            while (true) {
                int numRead = inStream.Read(buf2, pos, 4096);
                if (numRead <= 0) {
                    break;
                }
                pos += numRead;
            }

            for (int i = 0; i < buf.Length; ++i) {
                Assertion.AssertEquals(buf2[i], buf[i]);
            }
        }
开发者ID:foresightbrand,项目名称:brandqq,代码行数:30,代码来源:GZipTests.cs

示例4: TestGZip

		public void TestGZip()
		{
			MemoryStream ms = new MemoryStream();
			GZipOutputStream outStream = new GZipOutputStream(ms);

			byte[] buf = new byte[100000];
			System.Random rnd = new Random();
			rnd.NextBytes(buf);

			outStream.Write(buf, 0, buf.Length);
			outStream.Flush();
			outStream.Finish();

			ms.Seek(0, SeekOrigin.Begin);

			GZipInputStream inStream = new GZipInputStream(ms);
			byte[] buf2 = new byte[buf.Length];
			int currentIndex = 0;
			int count = buf2.Length;
			
			while (true) {
				int numRead = inStream.Read(buf2, currentIndex, count);
				if (numRead <= 0) {
					break;
				}
				currentIndex += numRead;
				count -= numRead;
			}

			Assert.AreEqual(0, count);
			
			for (int i = 0; i < buf.Length; ++i) {
				Assert.AreEqual(buf2[i], buf[i]);
			}
		}
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:35,代码来源:GZipTests.cs

示例5: Decompress

 private static byte[] Decompress(byte[] compressed)
 {
     using (var compressedMemoryStream = new MemoryStream(compressed))
     {
         var gZipInputStream = new GZipInputStream(compressedMemoryStream);
         try
         {
             using (var unCompressedStream = new MemoryStream())
             {
                 var noOfBytesReadTotal = 0;
                 const int blockSize = 2048;
                 var byteBlock = new byte[blockSize];
                 while (true)
                 {
                     var noOfBytesRead = gZipInputStream.Read(byteBlock, 0, byteBlock.Length);
                     if (noOfBytesRead <= 0)
                     {
                         break;
                     }
                     noOfBytesReadTotal += noOfBytesRead;
                     unCompressedStream.Write(byteBlock, 0, noOfBytesRead);
                 }
                 var decompressedWithoutTrailingZeros =
                     unCompressedStream.GetBuffer().Take(noOfBytesReadTotal);
                 return decompressedWithoutTrailingZeros.ToArray();
             }
         }
         finally
         {
             gZipInputStream.Close();
         }
     }
 }
开发者ID:1pindsvin,项目名称:yagni,代码行数:33,代码来源:UudecodedUnGZipper.cs

示例6: Decompress

        public string Decompress(string filename)
        {
            StringBuilder result = null;

            try
            {
                Stream s = new GZipInputStream(File.OpenRead(filename));

                result = new StringBuilder(8192);
                UTF7Encoding encoding = new UTF7Encoding(true);

                int size = 2048;
                byte[] writeData = new byte[2048];
                while (true)
                {
                    size = s.Read(writeData, 0, size);
                    if (size > 0)
                    {
                       result.Append(encoding.GetString(writeData,0,size));
                    }
                    else
                    {
                        break;
                    }
                }
                s.Close();

            } // end try
            catch (GZipException)
            {
                throw new Exception("Error: The file being read contains invalid data.");
            }
            catch (FileNotFoundException)
            {
                throw new Exception("Error:The file specified was not found.");
            }
            catch (ArgumentException)
            {
                throw new Exception("Error: path is a zero-length string, contains only white space, or contains one or more invalid characters");
            }
            catch (PathTooLongException)
            {
                throw new Exception("Error: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.");
            }
            catch (DirectoryNotFoundException)
            {
                throw new Exception("Error: The specified path is invalid, such as being on an unmapped drive.");
            }
            catch (IOException)
            {
                throw new Exception("Error: An I/O error occurred while opening the file.");
            }
            catch (UnauthorizedAccessException)
            {
                throw new Exception("Error: path specified a file that is read-only, the path is a directory, or caller does not have the required permissions.");
            }

            return result.ToString();
        }
开发者ID:BackupTheBerlios,项目名称:dufftv-svn,代码行数:59,代码来源:GzipDecompressor.cs

示例7: CreateReader

 protected override void CreateReader()
 {
     _logFileStream = new GZipInputStream(File.Open(_logFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
     if (_currentPosition > 0)
     {
         long seekPosition = 0;
         int readBlockSize = 2;//1024*1024;
         byte[] temp = new byte[readBlockSize];
         while (seekPosition < _currentPosition - readBlockSize)
         {
             _logFileStream.Read(temp, 0, readBlockSize);
             seekPosition += readBlockSize;
         }
         _logFileStream.Read(temp, 0, (int)(_currentPosition - seekPosition));
     }
     _logFileStreamReader = new StreamReader(_logFileStream, _logFileEncoding);
 }
开发者ID:demonix,项目名称:KeClientTracer,代码行数:17,代码来源:GzWebLogReader.cs

示例8: ArcFileSystem

        public ArcFileSystem()
        {
            data = new byte[90016];

            GZipInputStream gzipStream = new GZipInputStream(new FileStream("Assets/SilentHill3/Archives/arc.arc", FileMode.Open, FileAccess.Read));

            gzipStream.Read(data, 0, 90016);

            ReadAll();
        }
开发者ID:JokieW,项目名称:ShiningHill,代码行数:10,代码来源:ArcFileSystem.cs

示例9: DecompressDataSet

        /// <summary>
        /// Decompresses specified DataSet data what is compressed with GZIP.
        /// </summary>
        /// <param name="source">Stream to decompress.</param>
        /// <returns>Returns decompressed DataSet.</returns>
        public static DataSet DecompressDataSet(Stream source)
        {
            source.Position = 0;

            GZipInputStream gzip = new GZipInputStream(source);

            MemoryStream retVal = new MemoryStream();
            byte[] buffer = new byte[8000];
            int readedCount = gzip.Read(buffer,0,buffer.Length);
            while(readedCount > 0){
                // Store current zipped data block
                retVal.Write(buffer,0,readedCount);

                // Read next data block
                readedCount = gzip.Read(buffer,0,buffer.Length);
            }

            retVal.Position = 0;
            DataSet ds = new DataSet();
            ds.ReadXml(retVal);

            return ds;

            /* mono won't support compression
            GZipStream gzip = new GZipStream(source,CompressionMode.Decompress);

            MemoryStream retVal = new MemoryStream();
            byte[] buffer = new byte[8000];
            int readedCount = gzip.Read(buffer,0,buffer.Length);
            while(readedCount > 0){
                // Store current zipped data block
                retVal.Write(buffer,0,readedCount);

                // Read next data block
                readedCount = gzip.Read(buffer,0,buffer.Length);
            }

            retVal.Position = 0;
            DataSet ds = new DataSet();
            ds.ReadXml(retVal);

            return ds;*/
        }
开发者ID:dioptre,项目名称:nkd,代码行数:48,代码来源:Utils.cs

示例10: DeCompress

    public static byte[] DeCompress( byte[] bytesToDeCompress )
    {
        byte[] rebyte = new byte[ bytesToDeCompress.Length * 20 ];

        MemoryStream ms = new MemoryStream( bytesToDeCompress );
        MemoryStream outStream = new MemoryStream();

        GZipInputStream s = new GZipInputStream( ms );
        int read = s.Read( rebyte , 0 , rebyte.Length );
        while ( read > 0 )
        {
            outStream.Write( rebyte, 0 , read );
            read = s.Read( rebyte , 0, rebyte.Length );
        }

        s.Close();

        return outStream.ToArray();
    }
开发者ID:GHunique,项目名称:MyU3dFrame,代码行数:19,代码来源:GameDefine.cs

示例11: ComputeHashFromGz

 private static string ComputeHashFromGz(string filename)
 {
     string newHash;
     using (GZipInputStream logFileStream = new GZipInputStream(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
     {
         byte[] headBytes = new byte[BytesToRead];
         logFileStream.Read(headBytes, 0, BytesToRead);
         SHA1 sha1 = SHA1.Create();
         newHash = BitConverter.ToString(sha1.ComputeHash(headBytes));
     }
     return newHash;
 }
开发者ID:demonix,项目名称:KeClientTracer,代码行数:12,代码来源:RotatedLog.cs

示例12: unzip

    public string unzip(byte[] input)
    {
        using (MemoryStream memory = new MemoryStream()) {
            using (GZipInputStream gzip = new GZipInputStream(new MemoryStream(input))) {
                int n = 0;
                byte[] temp = new byte[1024];

                while ((n = gzip.Read(temp, 0, temp.Length)) != 0)
                    memory.Write (temp, 0, n);
            }//using

            return Encoding.UTF8.GetString (memory.ToArray ());
        }//using
    }
开发者ID:yinweli,项目名称:project_unity_example,代码行数:14,代码来源:Zip.cs

示例13: Uncompression

 /// <summary>
 /// 解压缩
 /// </summary>
 public static byte[] Uncompression(byte[] src)
 {
     if (!IsGZip(src)) return src;
     GZipInputStream gis = new GZipInputStream(new MemoryStream(src));
     MemoryStream ms = new MemoryStream();
     int count = 0;
     byte[] tmp = new byte[4096];
     while ((count = gis.Read(tmp, 0, tmp.Length)) > 0)
     {
         ms.Write(tmp, 0, count);
     }
     gis.Close();
     return ms.ToArray();
 }
开发者ID:zeronely,项目名称:View,代码行数:17,代码来源:GZipUtil.cs

示例14: returnUnZippedString

 public static string returnUnZippedString(byte[] zippedByteArrayToUnzip)
 {
     MemoryStream memStream = new MemoryStream(zippedByteArrayToUnzip);
     GZipInputStream objGZipInputStream = new GZipInputStream(memStream);
     int totalNumberOfBytesRead = 0;
     StringWriter unZippedData = new StringWriter();
     while (true)
     {
         byte[] tempUncompressedData = new byte[65536];
         int numberOfBytesProcessed = objGZipInputStream.Read(tempUncompressedData,0,65536);
         if (0 == numberOfBytesProcessed) break;
         unZippedData.Write(Encoding.UTF8.GetChars(tempUncompressedData));
         totalNumberOfBytesRead += numberOfBytesProcessed;
     }
     return unZippedData.ToString();
 }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:16,代码来源:zip.cs

示例15: GUnzip

        public string GUnzip(byte[] gzBuffer)
        {
            using (var ms = new MemoryStream())
            {
                var msgLength = BitConverter.ToInt32(gzBuffer, 0);
                ms.Write(gzBuffer, 4, gzBuffer.Length - 4);

                var buffer = new byte[msgLength];

                ms.Position = 0;
                using (var zipStream = new GZipInputStream(ms))
                {
                    zipStream.Read(buffer, 0, buffer.Length);
                }

                return Encoding.UTF8.GetString(buffer);
            }
        }
开发者ID:Wolfium,项目名称:ServiceStack-1,代码行数:18,代码来源:ICSharpGZipProvider.cs


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