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


C# Inflater.Reset方法代码示例

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


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

示例1: ReadArchive

		/// <summary>
		/// Reads a MPK from a binary reader
		/// </summary>
		/// <param name="rdr">The binary reader pointing to the MPK</param>
		private void ReadArchive(BinaryReader rdr)
		{
			_files.Clear();

			_crc.Value = 0;
			_sizeDir = 0;
			_sizeName = 0;
			_numFiles = 0;

			var buf = new byte[16];
			rdr.Read(buf, 0, 16);

			for (byte i = 0; i < 16; ++i)
			{
				buf[i] ^= i;
			}

			_crc.Value = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
			_sizeDir = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
			_sizeName = ((buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11]);
			_numFiles = ((buf[12] << 24) | (buf[13] << 16) | (buf[14] << 8) | buf[15]);

			buf = new byte[_sizeName];
			rdr.Read(buf, 0, _sizeName);

			var inf = new Inflater();
			inf.SetInput(buf);
			buf = new byte[1024];
			inf.Inflate(buf);
			buf[inf.TotalOut] = 0;

			_name = Marshal.ConvertToString(buf);

			long totalin = 0;
			buf = ReadDirectory(rdr, ref totalin);

			using (var directory = new MemoryStream(buf))
			{
				long pos = rdr.BaseStream.Position;
				long len = rdr.BaseStream.Seek(0, SeekOrigin.End);
				rdr.BaseStream.Position = pos;

				buf = new byte[len - pos];
				rdr.Read(buf, 0, buf.Length);

				using (var files = new MemoryStream(buf))
				{
					rdr.BaseStream.Position = pos - totalin;
					buf = new byte[totalin];
					rdr.Read(buf, 0, buf.Length);

					var crc = new Crc32();
					crc.Reset();
					crc.Update(buf);

					if (crc.Value != _crc.Value)
					{
						throw new Exception("Invalid or corrupt MPK");
					}

					while (directory.Position < directory.Length && files.Position < files.Length)
					{
						crc.Reset();

						buf = new byte[MPKFileHeader.MaxSize];
						directory.Read(buf, 0, MPKFileHeader.MaxSize);

						MPKFileHeader hdr;

						using (var hdrStream = new MemoryStream(buf))
						{
							using (var hdrRdr = new BinaryReader(hdrStream, Encoding.UTF8))
							{
								hdr = new MPKFileHeader(hdrRdr);
							}
						}

						var compbuf = new byte[hdr.CompressedSize];
						files.Read(compbuf, 0, compbuf.Length);

						crc.Update(compbuf, 0, compbuf.Length);

						inf.Reset();
						inf.SetInput(compbuf, 0, compbuf.Length);
						buf = new byte[hdr.UncompressedSize];
						inf.Inflate(buf, 0, buf.Length);

						var file = new MPKFile(compbuf, buf, hdr);

						if (crc.Value != hdr.CRC.Value)
						{
							OnInvalidFile(file);
							continue;
						}

						_files.Add(hdr.Name.ToLower(), file);
//.........这里部分代码省略.........
开发者ID:mynew4,项目名称:DOLSharp,代码行数:101,代码来源:MPK.cs

示例2: CopyTo

			public void CopyTo(Stream dest)
			{
				if ((fileDes.Flags & FileCompressed) != 0)
				{
					var inf = new Inflater(true);
					var buffer = new byte[165535];
					do
					{
						var bytesToExtract = cabFile.ReadUInt16();
						RemainingArchiveStream -= 2u;
						RemainingFileStream -= 2u;
						inf.SetInput(GetBytes(bytesToExtract));
						RemainingFileStream -= bytesToExtract;
						while (!inf.IsNeedingInput)
						{
							var inflated = inf.Inflate(buffer);
							dest.Write(buffer, 0, inflated);
						}

						inf.Reset();
					}
					while (RemainingFileStream > 0);
				}
				else
				{
					do
					{
						RemainingFileStream -= RemainingArchiveStream;
						dest.Write(GetBytes(RemainingArchiveStream), 0, (int)RemainingArchiveStream);
					}
					while (RemainingFileStream > 0);
				}
			}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:33,代码来源:InstallShieldCABExtractor.cs

示例3: CopyTo

            public void CopyTo(Stream output, Action<int> onProgress)
            {
                if (file.Flags.HasFlag(CABFlags.FileCompressed))
                {
                    var inf = new Inflater(true);
                    var buffer = new byte[165535];
                    do
                    {
                        var bytesToExtract = currentVolume.ReadUInt16();
                        remainingInArchive -= 2;
                        toExtract -= 2;
                        inf.SetInput(GetBytes(bytesToExtract));
                        toExtract -= bytesToExtract;
                        while (!inf.IsNeedingInput)
                        {
                            if (onProgress != null)
                                onProgress((int)(100 * output.Position / file.ExpandedSize));

                            var inflated = inf.Inflate(buffer);
                            output.Write(buffer, 0, inflated);
                        }

                        inf.Reset();
                    } while (toExtract > 0);
                }
                else
                {
                    do
                    {
                        if (onProgress != null)
                            onProgress((int)(100 * output.Position / file.ExpandedSize));

                        toExtract -= remainingInArchive;
                        output.Write(GetBytes(remainingInArchive), 0, (int)remainingInArchive);
                    } while (toExtract > 0);
                }
            }
开发者ID:OpenRA,项目名称:OpenRA,代码行数:37,代码来源:InstallShieldCABCompression.cs

示例4: release

 /**
  * Release an inflater previously obtained from this cache.
  *
  * @param i
  *            the inflater to return. May be null, in which case this method
  *            does nothing.
  */
 public void release(Inflater i)
 {
     if (i != null)
     {
         i.Reset();
         releaseImpl(i);
      }
 }
开发者ID:georgeck,项目名称:GitSharp,代码行数:15,代码来源:InflaterCache.cs

示例5: Inflate

        // make string large to orginal size
        public string Inflate(string input)
        {
            byte[] inputData = System.Convert.FromBase64String(input);
            Inflater inflater = new Inflater(false);
            using (var inputStream = new MemoryStream(inputData))
            using (var ms = new MemoryStream())
            {
                var inputBuffer = new byte[4096];
                var outputBuffer = new byte[4096];

                while (inputStream.Position < inputData.Length)
                {
                    var read = inputStream.Read(inputBuffer, 0, inputBuffer.Length);

                    inflater.SetInput(inputBuffer, 0, read);

                    while (inflater.IsNeedingInput == false)
                    {
                        var written = inflater.Inflate(outputBuffer, 0, outputBuffer.Length);

                        if (written == 0)
                            break;

                        ms.Write(outputBuffer, 0, written);
                    }

                    if (inflater.IsFinished == true)
                        break;
                }

                inflater.Reset();

                return Convert.ToBase64String( ms.ToArray());
            }
        }
开发者ID:noHero123,项目名称:guildchat.mod,代码行数:36,代码来源:Cryptomat.cs

示例6: Release

 /// <summary>Release an inflater previously obtained from this cache.</summary>
 /// <remarks>Release an inflater previously obtained from this cache.</remarks>
 /// <param name="i">
 /// the inflater to return. May be null, in which case this method
 /// does nothing.
 /// </param>
 public static void Release(Inflater i)
 {
     if (i != null)
     {
         i.Reset();
         if (ReleaseImpl(i))
         {
             i.Finish();
         }
     }
 }
开发者ID:sharwell,项目名称:ngit,代码行数:17,代码来源:InflaterCache.cs

示例7: ExtractFile

        public void ExtractFile(string filename, Stream output, Action<int> onProgress = null)
        {
            var file = files.FirstOrDefault(f => f.FileName == filename);
            if (file == null)
                throw new FileNotFoundException(filename);

            var folder = folders[file.FolderIndex];
            stream.Seek(folder.BlockOffset, SeekOrigin.Begin);

            var inflater = new Inflater(true);
            var buffer = new byte[4096];
            var decompressedBytes = 0;
            for (var i = 0; i < folder.BlockCount; i++)
            {
                if (onProgress != null)
                    onProgress((int)(100 * output.Position / file.DecompressedLength));

                // Ignore checksums
                stream.Position += 4;
                var blockLength = stream.ReadUInt16();
                stream.Position += 4;

                using (var batch = new MemoryStream(stream.ReadBytes(blockLength - 2)))
                using (var inflaterStream = new InflaterInputStream(batch, inflater))
                {
                    int n;
                    while ((n = inflaterStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        var offset = Math.Max(0, file.DecompressedOffset - decompressedBytes);
                        var count = Math.Min(n - offset, file.DecompressedLength - decompressedBytes);
                        if (offset < n)
                            output.Write(buffer, (int)offset, (int)count);

                        decompressedBytes += n;
                    }
                }

                inflater.Reset();
            }
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:40,代码来源:MSCabCompression.cs


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