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


C# Zlib.ZlibStream类代码示例

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


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

示例1: Comp

        public static byte[] Comp(byte[] input)
        {
            using (var sourceStream = new MemoryStream(input))
            {
                using (var compressed = new MemoryStream())
                {
                    using (var zipSteam = new ZlibStream(compressed, CompressionMode.Compress, CompressionLevel.Level9, true))
                    {
                        zipSteam.FlushMode = FlushType.Full;

                        //var buffer = new byte[1024];
                        //int len = sourceStream.Read(buffer, 0, buffer.Length);

                        //while (len > 0)
                        //{
                        //    zipSteam.Write(buffer, 0, len);
                        //    len = sourceStream.Read(buffer, 0, buffer.Length);
                        //}

                        sourceStream.CopyTo(zipSteam);

                        zipSteam.Flush();

                        return compressed.ToArray();
                    }
                }
            }
        }
开发者ID:Scrivener07,项目名称:moddingSuite,代码行数:28,代码来源:Compressing.cs

示例2: Packfile

        public Packfile(Stream stream, bool isStr2)
        {
            IsStr2 = isStr2;
            stream.Seek(0, SeekOrigin.Begin);
            FileData = stream.ReadStruct<PackfileFileData>();

            m_Files = new List<IPackfileEntry>();

            uint runningPosition = 0;
            List<PackfileEntryFileData> entryFileData = new List<PackfileEntryFileData>();
            for (int i = 0; i < FileData.NumFiles; i++)
            {
                PackfileEntryFileData data = stream.ReadStruct<PackfileEntryFileData>();

                if (IsCondensed && IsCompressed)
                {
                    data.Flags = 0;
                    data.Start = runningPosition;
                    runningPosition += data.Size;
                }
                else if (IsCondensed)
                {
                    data.Start = runningPosition;
                    runningPosition += data.Size.Align(16);
                }

                entryFileData.Add(data);
            }

            for (int i = 0; i < FileData.NumFiles; i++)
            {
                stream.Align(2);
                string filename = stream.ReadAsciiNullTerminatedString();
                stream.Seek(1, SeekOrigin.Current);
                m_Files.Add(new PackfileEntry(this, entryFileData[i], filename));
                stream.Align(2);
            }

            if (IsCondensed && IsCompressed)
            {
                DataOffset = 0;
                byte[] compressedData = new byte[FileData.CompressedDataSize];
                stream.Read(compressedData, 0, (int)FileData.CompressedDataSize);
                using (MemoryStream tempStream = new MemoryStream(compressedData))
                {
                    using (Stream s = new ZlibStream(tempStream, CompressionMode.Decompress, true))
                    {
                        byte[] uncompressedData = new byte[FileData.DataSize];
                        s.Read(uncompressedData, 0, (int)FileData.DataSize);
                        DataStream = new MemoryStream(uncompressedData);
                    }
                }
                
            }
            else
            {
                DataStream = stream;
                DataOffset = stream.Position;
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:60,代码来源:Packfile.cs

示例3: GetStream

        public Stream GetStream()
        {
            byte[] data = new byte[Data.Size];
            long offset = Packfile.DataOffset + Data.Start;
            Packfile.DataStream.Seek(offset, SeekOrigin.Begin);
            if (Data.Flags.HasFlag(PackfileEntryFlags.Compressed))
            {
                byte[] compressedData = new byte[Data.CompressedSize];
                Packfile.DataStream.Read(compressedData, 0, (int)Data.CompressedSize);
                using (MemoryStream tempStream = new MemoryStream(compressedData))
                {
                    using (Stream s = new ZlibStream(tempStream, CompressionMode.Decompress, true))
                    {
                        s.Read(data, 0, (int)Data.Size);
                    }
                }
            }
            else
            {
                Packfile.DataStream.Read(data, 0, (int)Data.Size);
            }

            MemoryStream ms = new MemoryStream(data);
            return ms;
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:25,代码来源:PackfileEntry.cs

示例4: Compress

        /// <summary>
        /// 지정된 데이타를 압축한다.
        /// </summary>
        /// <param name="input">압축할 Data</param>
        /// <returns>압축된 Data</returns>
        public override byte[] Compress(byte[] input) {
            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressStartMsg);

            // check input data
            if(input.IsZeroLength()) {
                if(IsDebugEnabled)
                    log.Debug(CompressorTool.SR.InvalidInputDataMsg);

                return CompressorTool.EmptyBytes;
            }

            byte[] output;

            using(var outStream = new MemoryStream(input.Length)) {
                using(var zlib = new ZlibStream(outStream, CompressionMode.Compress)) {
                    zlib.Write(input, 0, input.Length);
                }
                output = outStream.ToArray();
            }

            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);

            return output;
        }
开发者ID:debop,项目名称:NFramework,代码行数:31,代码来源:IonicZlibCompressor.cs

示例5: Compress

 public static byte[] Compress(byte[] input)
 {
     using (MemoryStream ms = new MemoryStream()) {
         using (ZlibStream zls = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestSpeed)) {
             zls.Write(input, 0, input.Length);
         }
         return ms.ToArray();
     }
 }
开发者ID:The6P4C,项目名称:Kalkimg,代码行数:9,代码来源:Utility.cs

示例6: Decompress

 public byte[] Decompress(Stream inputStream)
 {
     using (var zlibStream = new ZlibStream(inputStream, CompressionMode.Decompress))
     using (var outputStream = new MemoryStream())
     {
         zlibStream.WriteTo(outputStream);
         return outputStream.ToArray();
     }
 }
开发者ID:ryanwentzel,项目名称:DesignPatterns,代码行数:9,代码来源:ZLibCompression.cs

示例7: ReadChunk

        public static McaChunk ReadChunk(byte[] buffer, int dx, int dz)
        {
            //from mca file header
            int i = 4 * (dx + dz * 32);
            int offset = (buffer [i] << 16) | (buffer [i + 1] << 8) | (buffer [i + 2]);
            int sectors = buffer [i + 3];

            if (offset == 0 && sectors == 0)
                return null;

            Console.WriteLine("Read Chunk " + dx + "," + dz + " @ " + offset + ":" + sectors);

            if (offset == 0 || sectors == 0)
                throw new InvalidDataException("zero offset/sector");

            offset = offset << 12; //4096 = 2**12
            int length = EndianBitConverter.Big.ToInt32(buffer, offset); //byte length
            if (((length + 5 - 1) >> 12) + 1 != sectors)
                throw new InvalidDataException("Body length is larger than the sectors, " + length + " > " + (sectors * 4096));
            if (buffer [offset + 4] != 2)
                throw new NotImplementedException("Only support zlib compression");
            
            McaChunk mc = new McaChunk(dx, dz);

            MemoryStream ms = new MemoryStream(buffer, offset + 5, length);
            
            using (ZlibStream compressed = new ZlibStream(ms, CompressionMode.Decompress))
            {
                EndianBinaryReader r = new EndianBinaryReader(EndianBitConverter.Big, compressed);
                mc.Tag = Tag.ReadTag(r);
            }
            
            return mc;
        }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:34,代码来源:McaChunk.cs

示例8: uncompress

        public void uncompress(Stream inStream, Stream outStream)
        {

            ZlibStream compressionStream = new ZlibStream(inStream, CompressionMode.Decompress, true);

            compressionStream.CopyTo(outStream);

        }
开发者ID:superkaka,项目名称:mycsharp,代码行数:8,代码来源:ZlibCompresser.cs

示例9: Decompress

        /// <summary>
        /// Decompress a byte array into another byte array of the specified size
        /// </summary>
        /// <param name="to_decompress">Data to decompress</param>
        /// <param name="size_uncompressed">Size of the data once decompressed</param>
        /// <returns>Decompressed data as a byte array</returns>

        public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
        {
            ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
            byte[] packetData_decompressed = new byte[size_uncompressed];
            stream.Read(packetData_decompressed, 0, size_uncompressed);
            stream.Close();
            return packetData_decompressed;
        }
开发者ID:corwinbass,项目名称:Minecraft-Console-Client,代码行数:15,代码来源:ZlibUtils.cs

示例10: compress

        public void compress(Stream inStream, Stream outStream)
        {

            ZlibStream compressionStream = new ZlibStream(outStream, CompressionMode.Compress, true);

            inStream.CopyTo(compressionStream);

            compressionStream.Close();

        }
开发者ID:superkaka,项目名称:mycsharp,代码行数:10,代码来源:ZlibCompresser.cs

示例11: CompressStream

		/// <summary>
		/// compress a stream<see cref="Stream"/>
		/// </summary>
		/// <param name="stream"></param>
		/// <returns></returns>
		public static Stream CompressStream(Stream stream)
		{
			var result = new MemoryStream();
			using (var zlibStream = new ZlibStream(result, CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestSpeed, true))
			{
				CopyStream(stream, zlibStream);
			}

			return result;
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:15,代码来源:CompressManager.Compress.cs

示例12: Compress

 /// <summary>
 /// Compress to CompressedData
 /// </summary>
 public static MemoryStream Compress(byte[] buffer)
 {
     var output = new MemoryStream();
     using (ZlibStream zout = new ZlibStream(output, CompressionMode.Compress))
     {
         zout.Write(buffer, 0, buffer.Length);
         zout.Flush();
     }
     return output;
 }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:13,代码来源:Compression.cs

示例13: Decompress

 public static byte[] Decompress(byte[] compressed, int uncompressedSize)
 {
     using (MemoryStream input = new MemoryStream(compressed))
     using (ZlibStream zin = new ZlibStream(input, CompressionMode.Decompress))
     {
         byte[] uncompressed = new byte[uncompressedSize];
         ReadBuffer(zin, uncompressed);
         return uncompressed;
     }
 }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:10,代码来源:Compression.cs

示例14: ExtractStream

		/// <summary>
		/// extract a stream
		/// </summary>
		/// <param name="decompressed"></param>
		/// <returns></returns>
		public static Stream ExtractStream(Stream decompressed)
		{
			decompressed.Seek(0, SeekOrigin.Begin);
			var result = new MemoryStream();

			using (var zlibStream = new ZlibStream(result, CompressionMode.Decompress, true))
			{
				CopyStream(decompressed, zlibStream);
				return result;
			}
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:16,代码来源:CompressManager.Extract.cs

示例15: ReadCompressedID

 public static byte ReadCompressedID(byte[] compressed)
 {
     using (MemoryStream input = new MemoryStream(compressed))
     using (ZlibStream zin = new ZlibStream(input, CompressionMode.Decompress))
     {
         int val = zin.ReadByte();
         if (val < 0)
             throw new InvalidDataException();
         return (byte)val;
     }
 }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:11,代码来源:Compression.cs


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