• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Streams.InflaterInputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



InflaterInputStream类属于ICSharpCode.SharpZipLib.Zip.Compression.Streams命名空间,在下文中一共展示了InflaterInputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Decode

        private Stream Decode()
        {
            Stream stream;

            if (Encoding != "base64")
                throw new Exception("TmxMapperPCL.Data: Only Base64-encoded data is supported.");

            var rawData = Convert.FromBase64String(Value);
            var memStream = new MemoryStream(rawData);

            if (Compression == "gzip")
                stream = new GZipInputStream(memStream);
            else if (Compression == "zlib")
                stream = new InflaterInputStream(memStream);
            else if (Compression != null)
                throw new Exception("TmxMapperPCL.Data: Unknown compression.");
            else
                stream = memStream;

            var outputStream = new MemoryStream();
            stream.CopyTo(outputStream);
            stream = outputStream;

            return stream;
        }
开发者ID:PokeD,项目名称:TMXParserPCL,代码行数:25,代码来源:Data.cs


示例2: CloseInflatorWithNestedUsing

        public void CloseInflatorWithNestedUsing()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = Environment.TickCount.ToString();
                store.CreateDirectory(tempFile);

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                using (IsolatedStorageFileStream diskFile = store.CreateFile(tempFile))
                using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
                using (StreamWriter textWriter = new StreamWriter(deflator))
                {
                    textWriter.Write("Hello");
                    textWriter.Flush();
                }

                using (IsolatedStorageFileStream diskFile = store.OpenFile(tempFile, FileMode.Open))
                using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
                using (StreamReader textReader = new StreamReader(deflator))
                {
                    char[] buffer = new char[5];
                    int readCount = textReader.Read(buffer, 0, 5);
                    Assert.AreEqual(5, readCount);

                    StringBuilder b = new StringBuilder();
                    b.Append(buffer);
                    Assert.AreEqual("Hello", b.ToString());

                }

                store.CreateFile(tempFile);
            }
        }
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:33,代码来源:InflaterDeflaterTestSuite_FileSystem.cs


示例3: Deserialize

        public static void Deserialize(Stream stream, PiaFile piaFile)
        {
            if (stream == null)
                throw new ArgumentNullException("Stream");

            if (piaFile == null)
                throw new ArgumentNullException("PiaFile");

            try
            {
                // Header
                var headerBytes = new Byte[48]; // Ignore 12 byte checksum
                stream.Read(headerBytes, 0, headerBytes.Length);
                var headerString = Encoding.Default.GetString(headerBytes);
                piaFile.Header = new PiaHeader(headerString);

                // Inflation
                string inflatedString;
                stream.Seek(60, SeekOrigin.Begin);

                using (var zStream = new InflaterInputStream(stream))
                {
                    var sr = new StreamReader(zStream, Encoding.Default);
                    inflatedString = sr.ReadToEnd();
                }

                // Nodes
                piaFile.Owner = piaFile;
                _deserializeNode(piaFile, inflatedString);
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:phusband,项目名称:PiaNO,代码行数:35,代码来源:PiaSerializer.cs


示例4: Decompress

        public void Decompress(Stream source, Stream destination)
        {
            var inflater = new InflaterInputStream(source, new Inflater(true));

            var dataBuffer = new byte[CopyBufferSize];
            StreamUtils.Copy(inflater, destination, dataBuffer);
        }
开发者ID:tjhorner,项目名称:gtaivtools,代码行数:7,代码来源:CompressionDeflateCodec.cs


示例5: ExpandString

        /// <summary>
        /// Expands (de-compresses) a string.
        /// </summary>
        /// <param name="value">The string to expanded.</param>
        /// <returns>The expanded string.</returns>
        public string ExpandString(string value)
        {
            // The input value must be non-null
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var outputData = string.Empty;
            var inputData = Convert.FromBase64String(value);
            using (var inputStream = new MemoryStream(inputData))
            {
                using (var outputStream = new MemoryStream())
                {
                    // Zip the string
                    using (var zipStream = new InflaterInputStream(inputStream))
                    {
                        zipStream.IsStreamOwner = false;
                        StreamUtils.Copy(zipStream, outputStream, new byte[4096]);
                    }

                    // Convert to a string
                    outputData = UTF8Encoding.UTF8.GetString(outputStream.GetBuffer(), 0, Convert.ToInt32(outputStream.Length));
                }
            }

            // Return the compressed string
            return outputData;
        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:34,代码来源:ZipCompressionService.cs


示例6: Inflate

 internal static byte[] Inflate(byte[] buffer)
 {
     InflaterInputStream inflaterStream = new InflaterInputStream(new MemoryStream(buffer));
     MemoryStream outputStream = new MemoryStream();
     inflaterStream.CopyTo(outputStream);
     return outputStream.ToArray();
 }
开发者ID:kkkkyue,项目名称:FtexTool,代码行数:7,代码来源:ZipUtility.cs


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


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


示例9: GetDimensions

    public Rectangle GetDimensions(Stream stream)
    {
        Stream inputStream = null;
        byte[] signature = new byte[8];
        byte[] rect = new byte[8];
        stream.Read(signature, 0, 8);
        if ("CWS" == System.Text.Encoding.ASCII.GetString(signature, 0, 3))
        {
            inputStream = new InflaterInputStream(stream);
        }
        else
        {
            inputStream = stream;
        }

        inputStream.Read(rect, 0, 8);
        int nbits = rect[0] >> 3;
        rect[0] = (byte)(rect[0] & 0x07);
        String bits = ByteArrayToBitString(rect);
        bits = bits.Remove(0, 5);
        int[] dims = new int[4];
        for (int i = 0; i < 4; i++)
        {
            char[] dest = new char[nbits];
            bits.CopyTo(0, dest, 0, bits.Length > nbits ? nbits : bits.Length);
            bits = bits.Remove(0, bits.Length > nbits ? nbits : bits.Length);
            dims[i] = BitStringToInteger(new String(dest)) / 20;
        }

        return new Rectangle(0, 0, dims[1] - dims[0], dims[3] - dims[2]);
    }
开发者ID:hungtien408,项目名称:web-quanaotreem,代码行数:31,代码来源:SwfParser.cs


示例10: CloseInflatorWithNestedUsing

        public void CloseInflatorWithNestedUsing()
        {
            string tempFile = null;
            try {
                tempFile = Path.GetTempPath();
            } catch (SecurityException) {
            }

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
            using (FileStream diskFile = File.Create(tempFile))
            using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
            using (StreamWriter textWriter = new StreamWriter(deflator)) {
                textWriter.Write("Hello");
                textWriter.Flush();
            }

            using (FileStream diskFile = File.OpenRead(tempFile))
            using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
            using (StreamReader textReader = new StreamReader(deflator)) {
                char[] buffer = new char[5];
                int readCount = textReader.Read(buffer, 0, 5);
                Assert.AreEqual(5, readCount);

                var b = new StringBuilder();
                b.Append(buffer);
                Assert.AreEqual("Hello", b.ToString());

            }

            File.Delete(tempFile);
        }
开发者ID:Zo0pZ,项目名称:SharpZipLib,代码行数:33,代码来源:InflaterDeflaterTests.cs


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


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


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


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


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


示例16: Decompress

 /// <summary>
 /// ��ѹ�ֽ�������
 /// </summary>
 /// <param name="val">��������ֽ�������</param>
 /// <returns>���ؽ�ѹ�������</returns>
 public byte[] Decompress(byte[] val)
 {
     if (val[0] == 1) {
         Inflater inflater = new Inflater(true);
         using (InflaterInputStream decompressStream = new InflaterInputStream(new MemoryStream(UnwrapData(val)), inflater)) {
             return ArrayHelper.ReadAllBytesFromStream(decompressStream);
         }
     }
     else
         return UnwrapData(val);
 }
开发者ID:wuyingyou,项目名称:uniframework,代码行数:16,代码来源:Compressor.cs


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


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


示例19: DecompressZlib

 public static byte[] DecompressZlib(byte[] input)
 {
     MemoryStream source = new MemoryStream(input);
     byte[] result = null;
     using (MemoryStream outStream = new MemoryStream())
     {
         using (InflaterInputStream inf = new InflaterInputStream(source))
         {
             inf.CopyTo(outStream);
         }
         result = outStream.ToArray();
     }
     return result;
 }
开发者ID:zeroKilo,项目名称:Zlibber,代码行数:14,代码来源:Form1.cs


示例20: Uncompress

 public static int Uncompress(ref byte[] Data)
 {
     int maxsize = Data.Length * 10 + 300;
     if (maxsize > 50000) maxsize = 50000;
     byte[] outputData = new byte[maxsize];
     MemoryStream dataStream = new MemoryStream(Data);
     InflaterInputStream inflater = new InflaterInputStream(dataStream);
     //int res=descompresor.Read(packetsalida,0,packetsalida.Length);
     //if (res>0)
     int res;
     int resTotal = 0;
     MemoryStream uncompressedStream = new MemoryStream();
     do
     {
         if (inflater.Position == Data.Length) res = 0;
         else
             try
             {
                 res = inflater.Read(outputData, 0, outputData.Length);
             }
             catch
             {
                 res = 0;
             }
         if (res > 0)
         {
             uncompressedStream.Write(outputData, 0, res);
         }
         resTotal += res;
     }
     while (res > 0);
     if (resTotal == 0)
     {
         return 0;
     }
     else
     {
         inflater.Close();
         inflater = null;
         dataStream.Close();
         dataStream = null;
         Data = null;
         Data = new byte[resTotal];
         uncompressedStream.Seek(0, SeekOrigin.Begin);
         uncompressedStream.Read(Data, 0, resTotal);
         uncompressedStream.Close();
         uncompressedStream = null;
         return resTotal;
     }
 }
开发者ID:elnomade,项目名称:hathi,代码行数:50,代码来源:CReceivedCompressedBlock.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Streams.StreamManipulator类代码示例发布时间:2022-05-26
下一篇:
C# Streams.DeflaterOutputStream类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap