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

C# Zlib.ZlibStream类代码示例

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

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



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


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


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


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


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


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


示例16: ZibCompress

 public static byte[] ZibCompress(byte[] input)
 {
     using (var ms = new System.IO.MemoryStream())
     {
         using (var zs = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, true))
         {
             zs.Write(input, 0, input.Length);
         }
         return ms.ToArray();
     }
 }
开发者ID:RobertHu,项目名称:TraderServer,代码行数:11,代码来源:ZlibHelper.cs


示例17: DecompressResponse

        public void DecompressResponse()
        {
            if (string.IsNullOrEmpty(this.ZNO))
            {
                return;
            }

            MemoryStream compressMetadataCollection = null;
            MemoryStream decompressedMetadataCollection = null;
            ZlibStream decompressStream = null;

            try
            {
                byte[] compressedMetadataCollectionBytes = Convert.FromBase64String(this.ZNO);
                compressMetadataCollection = new MemoryStream(compressedMetadataCollectionBytes);
                byte[] buffer = new byte[1024];
                int numBytesRead = 0;
                bool start = true;

                decompressedMetadataCollection = new MemoryStream();

                using (decompressStream = new ZlibStream(compressMetadataCollection, CompressionMode.Decompress))
                {
                    while (start || numBytesRead > 0)
                    {
                        numBytesRead = decompressStream.Read(buffer, 0, buffer.Length);

                        if (numBytesRead > 0)
                        {
                            decompressedMetadataCollection.Write(buffer, 0, numBytesRead);
                        }

                        start = false;
                    }
                }

                decompressedMetadataCollection.Position = 0;

                DataContractSerializer deserializer = new DataContractSerializer(typeof(CompressedResponseTuple));

                CompressedResponseTuple responseTuple = deserializer.ReadObject(decompressedMetadataCollection) as CompressedResponseTuple;

                Nodes = responseTuple.Nodes;
                Relationships = responseTuple.Relationships;
            }
            finally
            {
                if (decompressedMetadataCollection != null)
                {
                    decompressedMetadataCollection.Dispose();
                    decompressedMetadataCollection = null;
                }
            }
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:54,代码来源:QueryResponse.cs


示例18: Compress

 internal static byte[] Compress(byte[] buffer)
 {
     using (var output = new MemoryStream())
     {
         using (Stream compressor = new ZlibStream(output, CompressionMode.Compress, CompressionLevel.BestCompression))
         {
             compressor.Write(buffer, 0, buffer.Length);
         }
         return output.ToArray();
     }
 }
开发者ID:engrin,项目名称:GzsTool,代码行数:11,代码来源:Compression.cs


示例19: ProcessFirmware

        public static Firmware ProcessFirmware(string path)
        {
            

           // JavaScriptSerializer serializer = new JavaScriptSerializer();

            Console.WriteLine("Read File " + path);

            // read the file
            StreamReader f = new StreamReader(File.OpenRead(path));
            //fw = serializer.Deserialize<Firmware>(f.ReadToEnd());
            fw = JSON.Instance.ToObject<Firmware>(f.ReadToEnd());
            f.Close();
            
            byte[] data = Convert.FromBase64String(fw.image);

            MemoryStream imagems = new MemoryStream(data, true);

            ZlibStream decompressionStream = new ZlibStream(imagems, CompressionMode.Decompress);


            int size = fw.image_size + (fw.image_size % 4);
            fw.imagebyte = new byte[size];

            for (int a = 0; a < fw.imagebyte.Length; a++)
            {
                fw.imagebyte[a] = 0xff;
            }

            try
            {
                decompressionStream.Read(fw.imagebyte, 0, fw.image_size);
            }
            catch { Console.WriteLine("Possible bad file - usualy safe to ignore"); }

            Console.WriteLine("image_size {0} size {1}",fw.image_size,size);

            
            BinaryWriter sw = new BinaryWriter(File.Open("px4fw.bin", FileMode.Create));

            foreach (byte by in fw.imagebyte)
            {
                sw.Write(by);
                //   Console.Write("{0:x2}", by);
            }

            sw.Close();
            
            // pad image to 4-byte length
            //while ((fw.imagebyte.Length % 4) != 0) {
            //fw.imagebyte. += b'\x00'

            return fw;
        }
开发者ID:RobertCL,项目名称:MissionPlanner,代码行数:54,代码来源:Firmware.cs


示例20: ZibCompress

 public static UnmanagedMemory ZibCompress(byte[] input)
 {
     using (var ms = new TraderMemoryStream(500 * 1024))
     {
         using (var zs = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, true))
         {
             zs.Write(input, 0, input.Length);
         }
         return ms.Buffer;
     }
 }
开发者ID:RobertHu,项目名称:-NewTraderServer,代码行数:11,代码来源:ZlibHelper.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# IrcDotNet.IrcChannel类代码示例发布时间:2022-05-26
下一篇:
C# Zlib.ZlibCodec类代码示例发布时间: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