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


C# InflaterInputStream.Read方法代码示例

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


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

示例1: TestInflateDeflate

        public void TestInflateDeflate()
        {
            MemoryStream ms = new MemoryStream();
            Deflater deflater = new Deflater(6);
            DeflaterOutputStream outStream = new DeflaterOutputStream(ms, deflater);

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

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

            ms.Seek(0, SeekOrigin.Begin);

            InflaterInputStream inStream = new InflaterInputStream(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:wuzhen,项目名称:SwfDecompiler,代码行数:31,代码来源:InflaterDeflaterTests.cs

示例2: DeCompress

        /// <summary>
        /// Decompresses an array of bytes.
        /// </summary>
        /// <param name="_pBytes">An array of bytes to be decompressed.</param>
        /// <returns>Decompressed bytes</returns>
        public static byte[] DeCompress(byte[] _pBytes)
        {
            InflaterInputStream inputStream = new InflaterInputStream(new MemoryStream(_pBytes));

            MemoryStream ms = new MemoryStream();
            Int32 mSize;

            byte[] mWriteData = new byte[4096];

            while (true)
            {
                mSize = inputStream.Read(mWriteData, 0, mWriteData.Length);
                if (mSize > 0)
                {
                    ms.Write(mWriteData, 0, mSize);
                }
                else
                {
                    break;
                }
            }

            inputStream.Close();
            return ms.ToArray();
        }
开发者ID:daxnet,项目名称:guluwin,代码行数:30,代码来源:DataCompression.cs

示例3: Decompress

        public string Decompress(string compressedString)
        {
            var uncompressedString = string.Empty;
            var totalLength = 0;
            var inputAsBytes = Convert.FromBase64String(compressedString);;
            var writeData = new byte[4096];
            var inputStream = new InflaterInputStream(new MemoryStream(inputAsBytes));

            for(;;)
            {
                var size = inputStream.Read(writeData, 0, writeData.Length);

                if (size > 0)
                {
                    totalLength += size;
                    uncompressedString += Encoding.UTF8.GetString(writeData, 0, size);
                }
                else
                {
                    break;
                }
            }

            inputStream.Close();

            return uncompressedString;
        }
开发者ID:benaston,项目名称:NCacheFacade,代码行数:27,代码来源:SharpZipStringCompressor.cs

示例4: Inflate

		void Inflate(MemoryStream ms, byte[] original, int level, bool zlib)
		{
			ms.Seek(0, SeekOrigin.Begin);
			
			Inflater inflater = new Inflater(!zlib);
			InflaterInputStream inStream = new InflaterInputStream(ms, inflater);
			byte[] buf2 = new byte[original.Length];

			int currentIndex  = 0;
			int count = buf2.Length;

			try
			{
				while (true) 
				{
					int numRead = inStream.Read(buf2, currentIndex, count);
					if (numRead <= 0) 
					{
						break;
					}
					currentIndex += numRead;
					count -= numRead;
				}
			}
			catch(Exception ex)
			{
				Console.WriteLine("Unexpected exception - '{0}'", ex.Message);
				throw;
			}

			if ( currentIndex != original.Length )
			{
				Console.WriteLine("Original {0}, new {1}", original.Length, currentIndex);
				Assert.Fail("Lengths different");
			}

			for (int i = 0; i < original.Length; ++i) 
			{
				if ( buf2[i] != original[i] )
				{
					string description = string.Format("Difference at {0} level {1} zlib {2} ", i, level, zlib);
					if ( original.Length < 2048 )
					{
						StringBuilder builder = new StringBuilder(description);
						for (int d = 0; d < original.Length; ++d)
						{
							builder.AppendFormat("{0} ", original[d]);
						}

						Assert.Fail(builder.ToString());
					}
					else
					{
						Assert.Fail(description);
					}
				}
			}
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:58,代码来源:InflaterDeflaterTests.cs

示例5: Decompress

 public void Decompress(ArraySegment<byte> input, ArraySegment<byte> output)
 {
     using (var gz = new InflaterInputStream(new MemoryStream(input.Array, input.Offset, input.Count)))
     {
         int read = gz.Read(output.Array, output.Offset, output.Count);
         if (read != output.Count)
             throw new Exception("Short read!");
     }
 }
开发者ID:AustinWise,项目名称:ZfsSharp,代码行数:9,代码来源:GZip.cs

示例6: Decompress

        public static byte[] Decompress(byte[] data, int final_size)
        {
            byte[] r = null;

            using (Stream s = new InflaterInputStream(new MemoryStream(data)))
                s.Read(r, 0, final_size);

            return r;
        }
开发者ID:hollow87,项目名称:Arca4,代码行数:9,代码来源:ZipLib.cs

示例7: UncompressStream

        public static byte[] UncompressStream(Stream stream, int filesize, int memsize)
        {

            BinaryReader r = new BinaryReader(stream);
            long end = stream.Position + filesize;

            byte[] header = r.ReadBytes(2);

            if (checking) if (header.Length != 2)
                    throw new InvalidDataException("Hit unexpected end of file at " + stream.Position);

            bool useDEFLATE = true;
            byte[] uncompressedData = null;

            if (header[0] == 0x78)
            {
                useDEFLATE = true;
            }
            else if (header[1] == 0xFB)
            {
                useDEFLATE = false;
            }
            else
            {
                throw new InvalidDataException("Unrecognized compression format");
            }

            if (useDEFLATE)
            {
                byte[] data = new byte[filesize];
                stream.Position -= 2; // go back to header
                stream.Read(data, 0, filesize);
                using (MemoryStream source = new MemoryStream(data))
                {
                    using (InflaterInputStream decomp = new InflaterInputStream(source))
                    {
                        uncompressedData = new byte[memsize];
                        decomp.Read(uncompressedData, 0, memsize);
                    }
                }
            }
            else
            {
                uncompressedData = OldDecompress(stream, header[0]);
            }

            long realsize = uncompressedData.Length;

            if (checking) if (realsize != memsize)
                    throw new InvalidDataException(String.Format(
                        "Resource data indicates size does not match index at 0x{0}.  Read 0x{1}.  Expected 0x{2}.",
                        stream.Position.ToString("X8"), realsize.ToString("X8"), memsize.ToString("X8")));

            return uncompressedData;

        }
开发者ID:dwalternatio,项目名称:Sims4Tools,代码行数:56,代码来源:Compression.cs

示例8: Decode

 public byte[] Decode(byte[] input, int decompressedSize)
 {
     InflaterInputStream stream = new InflaterInputStream(new MemoryStream(input));
     byte[] data = new byte[4096];
     MemoryStream outStream = new MemoryStream();
     int size;
     while ((size = stream.Read(data, 0, data.Length)) > 0)
     {
         outStream.Write(data, 0, size);
     }
     outStream.Capacity = (int)outStream.Length;
     return outStream.GetBuffer();
 }
开发者ID:thawk,项目名称:structorian,代码行数:13,代码来源:ZLibDecoder.cs

示例9: Decompress

 // Length = decompressed length
 public static byte[] Decompress(int Length, byte[] Data)
 {
     byte[] Output = new byte[Length];
     Stream s = new InflaterInputStream(new MemoryStream(Data));
     int Offset = 0;
     while(true)
     {
         int size = s.Read(Output, Offset, Length);
         if (size == Length) break;
         Offset += size;
         Length -= size;
     }
     return Output;
 }
开发者ID:remixod,项目名称:NetLibClient,代码行数:15,代码来源:Compression.cs

示例10: Decompress

 public static byte[] Decompress(string data)
 {
     byte[] array = null;
     if (data.StartsWith("ZipStream:"))
     {
         MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(data.Substring(10)));
         InflaterInputStream inflaterInputStream = new InflaterInputStream(memoryStream);
         BinaryReader binaryReader = new BinaryReader(memoryStream);
         int num = binaryReader.ReadInt32();
         array = new byte[num];
         inflaterInputStream.Read(array, 0, num);
         inflaterInputStream.Close();
         memoryStream.Close();
     }
     return array;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:16,代码来源:CompressionHelper.cs

示例11: Decompress

 public static void Decompress(ref GenericReader gr)
 {
     int uncompressedLength = gr.ReadInt32();
     byte[] output = new byte[gr.ReadInt32()];
     byte[] temp = gr.ReadBytes((int)gr.Remaining);
     gr.Close();
     Stream s = new InflaterInputStream(new MemoryStream(temp));
     int offset = 0;
     while (true)
     {
         int size = s.Read(output, offset, uncompressedLength);
         if (size == uncompressedLength) break;
         offset += size;
         uncompressedLength -= size;
     }
     gr = new GenericReader(new MemoryStream(output));
     //gr.BaseStream.Position = 0;
 }
开发者ID:arkanoid1,项目名称:mywowtools,代码行数:18,代码来源:a9_parser.cs

示例12: Inflate

        public string Inflate(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 InflaterInputStream(ms, new Inflater()))
                {
                    zipStream.Read(buffer, 0, buffer.Length);
                }

                return Encoding.UTF8.GetString(buffer);
            }
        }
开发者ID:EvgeniyProtas,项目名称:servicestack,代码行数:18,代码来源:ICSharpDeflateProvider.cs

示例13: Decompress

 public byte[] Decompress( byte[] bytes )
 {
     Stream stream = new InflaterInputStream( new MemoryStream( bytes ) );
     MemoryStream memory = new MemoryStream();
     int totalLength = 0;
     byte[] writeData = new byte[4096];
     while ( true )
     {
         int size = stream.Read( writeData, 0, writeData.Length );
         if ( size > 0 )
         {
             totalLength += size;
             memory.Write( writeData, 0, size );
         }
         else
             break;
     }
     stream.Close();
     return memory.ToArray();
 }
开发者ID:popovegor,项目名称:gt,代码行数:20,代码来源:GTCommonWebPage.cs

示例14: Decompress

 public static byte[] Decompress(byte[] bytes)
 {
     InflaterInputStream stream = new InflaterInputStream(new MemoryStream(bytes));
     MemoryStream memory = new MemoryStream();
     Byte[] writeData = new byte[4096];
     int size;
     while (true)
     {
         size = stream.Read(writeData, 0, writeData.Length);
         if (size > 0)
         {
             memory.Write(writeData, 0, size);
         }
         else
         {
             break;
         }
     }
     stream.Close();
     return memory.ToArray();
 }
开发者ID:mex868,项目名称:Nissi.Solution,代码行数:21,代码来源:Zip.cs

示例15: ProcessData

 public static MemoryStream ProcessData(byte[] data)
 {
     if (data == null)
     {
         return null;
     }
     MemoryStream baseInputStream = null;
     MemoryStream stream2;
     InflaterInputStream stream3 = null;
     try
     {
         baseInputStream = new MemoryStream(data);
         stream2 = new MemoryStream();
         stream3 = new InflaterInputStream(baseInputStream);
         byte[] buffer = new byte[data.Length];
         while (true)
         {
             int count = stream3.Read(buffer, 0, buffer.Length);
             if (count <= 0)
             {
                 break;
             }
             stream2.Write(buffer, 0, count);
         }
         stream2.Flush();
         stream2.Seek(0L, SeekOrigin.Begin);
     }
     finally
     {
         if (baseInputStream != null)
         {
             baseInputStream.Close();
         }
         if (stream3 != null)
         {
             stream3.Close();
         }
     }
     return stream2;
 }
开发者ID:n017,项目名称:NETDeob,代码行数:40,代码来源:UnZip.cs


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