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


C# DeflateStream.Write方法代码示例

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


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

示例1: 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()) {
                using(var deflate = new DeflateStream(outStream, CompressionMode.Compress, CompressionLevel.BestSpeed)) {
                    deflate.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,代码行数:30,代码来源:IonicDeflateCompressor.cs

示例2: DeflateEncoder

		/// <summary>Deflate encoder, compatible with .NET one but with bettern compression 
		/// ratio (in .NET 4.0, in .NET 4.5 they are identical).</summary>
		/// <param name="input">The input.</param>
		/// <returns>Compressed data.</returns>
		public static byte[] DeflateEncoder(byte[] input)
		{
			using (var ostream = new MemoryStream())
			{
				using (var zstream = new DeflateStream(ostream, CompressionMode.Compress))
				{
					zstream.Write(input, 0, input.Length);
					zstream.Flush();
				}
				return ostream.ToArray();
			}
		}
开发者ID:jinjingcai2014,项目名称:LibZ,代码行数:16,代码来源:DefaultCodecs.cs

示例3: CompressDeflate

        public static byte[] CompressDeflate(byte[] bytes)
        {
            using (var ms = new MemoryStream())
            {
                using (var zip = new DeflateStream(ms, CompressionMode.Compress, true))
                {
                    zip.Write(bytes, 0, bytes.Length);
                }

                return ms.ToArray();
            }
        }
开发者ID:venusdharan,项目名称:Titanium-Web-Proxy,代码行数:12,代码来源:Compression.cs

示例4: Deflate

        private static byte[] Deflate(byte[] bytes)
        {
            if (bytes == null) return new byte[0];

            using (var stream = new MemoryStream())
            {
                using (var compressor = new DeflateStream(stream,CompressionMode.Compress, CompressionLevel.BestSpeed))
                {
                    compressor.Write(bytes, 0, bytes.Length);
                }

                return stream.ToArray();
            }
        }
开发者ID:alexvance89,项目名称:tinder-api,代码行数:14,代码来源:DeflateCompressionAttribute.cs

示例5: DeflateByte

        public static byte[] DeflateByte(byte[] content)
        {
            if(null==content)
            {
                return null;
            }

            using (var stream = new MemoryStream())
            {
                using (var compressor = new DeflateStream(stream,CompressionMode.Compress,CompressionLevel.BestSpeed))
                {
                    compressor.Write(content,0,content.Length);
                }

                return stream.ToArray();
            }
        }
开发者ID:liujiekm,项目名称:MedicalInsuranceService,代码行数:17,代码来源:DeflateCompressionAttribute.cs

示例6: CompressBuffer

 public static byte[] CompressBuffer(byte[] buffer, ushort key, uint keyend)
 {
     byte[] compressed;
     using (var compressStream = new MemoryStream())
     using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
     {
         compressor.Write(buffer, 0, buffer.Length);
         compressor.Close();
         compressed = compressStream.ToArray();
     }
     byte[] returnbytes = new byte[compressed.Length + 6];
     byte[] kbyte = BitConverter.GetBytes(key);
     byte[] kebyte = BitConverter.GetBytes(keyend);
     Array.Copy(kbyte, 0, returnbytes, 0, kbyte.Length);
     Array.Copy(compressed, 0, returnbytes, 2, compressed.Length);
     Array.Copy(kebyte, 0, returnbytes, returnbytes.Length - 4, kebyte.Length);
     return returnbytes;
 }
开发者ID:Wroud,项目名称:Coob,代码行数:18,代码来源:ZlibHelper.cs

示例7: DeflateByte

        public static byte[] DeflateByte(byte[] str)
        {
            if (str == null)
            {
                return null;
            }

            using (var output = new MemoryStream())
            {
                using (
                    var compressor = new DeflateStream(
                    output, CompressionMode.Compress,
                    CompressionLevel.BestSpeed))
                {
                    compressor.Write(str, 0, str.Length);
                }

                return output.ToArray();
            }
        }
开发者ID:YuleSouza,项目名称:Loja,代码行数:20,代码来源:DeflateCompressionAttribute.cs

示例8: SaveMap

		public static void SaveMap()
		{
			bool isCloudSave = Main.ActivePlayerFileData.IsCloudSave;
			if (isCloudSave && SocialAPI.Cloud == null)
			{
				return;
			}
			if (!Main.mapEnabled || MapHelper.saveLock)
			{
				return;
			}
			string text = Main.playerPathName.Substring(0, Main.playerPathName.Length - 4);
			lock (MapHelper.padlock)
			{
				try
				{
					MapHelper.saveLock = true;
					try
					{
						if (!isCloudSave)
						{
							Directory.CreateDirectory(text);
						}
					}
					catch
					{
					}
					text = string.Concat(new object[]
					{
						text,
						Path.DirectorySeparatorChar,
						Main.worldID,
						".map"
					});
					Stopwatch stopwatch = new Stopwatch();
					stopwatch.Start();
					bool flag2 = false;
					if (!Main.gameMenu)
					{
						flag2 = true;
					}
					using (MemoryStream memoryStream = new MemoryStream(4000))
					{
						using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
						{
							using (DeflateStream deflateStream = new DeflateStream(memoryStream, 0))
							{
								int num = 0;
								byte[] array = new byte[16384];
								binaryWriter.Write(Main.curRelease);
								Main.MapFileMetadata.IncrementAndWrite(binaryWriter);
								binaryWriter.Write(Main.worldName);
								binaryWriter.Write(Main.worldID);
								binaryWriter.Write(Main.maxTilesY);
								binaryWriter.Write(Main.maxTilesX);
                                binaryWriter.Write((short)(419 + Main.ulterrariaTiles));//
                                binaryWriter.Write((short)225 + Main.ulterrariaWalls);
                                binaryWriter.Write((short)3);
                                binaryWriter.Write((short)256);
                                binaryWriter.Write((short)256);
                                binaryWriter.Write((short)256);
								byte b = 1;
								byte b2 = 0;
								int i;
                                for (i = 0; i < 419 + Main.ulterrariaTiles; i++)
								{
									if (MapHelper.tileOptionCounts[i] != 1)
									{
										b2 |= b;
									}
									if (b == 128)
									{
										binaryWriter.Write(b2);
										b2 = 0;
										b = 1;
									}
									else
									{
										b = (byte)(b << 1);
									}
								}
								if (b != 1)
								{
									binaryWriter.Write(b2);
								}
								i = 0;
								b = 1;
								b2 = 0;
                                while (i < 225 + Main.ulterrariaWalls)
								{
									if (MapHelper.wallOptionCounts[i] != 1)
									{
										b2 |= b;
									}
									if (b == 128)
									{
										binaryWriter.Write(b2);
										b2 = 0;
										b = 1;
									}
//.........这里部分代码省略.........
开发者ID:thegamingboffin,项目名称:Ulterraria_Reborn_GitHub,代码行数:101,代码来源:MapHelper.cs

示例9: lock

 /*public static void SaveMap()
 {
     bool isCloudSave = Main.ActivePlayerFileData.IsCloudSave;
     if (isCloudSave && SocialAPI.Cloud == null)
     {
         return;
     }
     if (!Main.mapEnabled || MapHelper.saveLock)
     {
         return;
     }
     string text = Main.playerPathName.Substring(0, Main.playerPathName.Length - 4);
     lock (MapHelper.padlock)
     {
         try
         {
             MapHelper.saveLock = true;
             try
             {
                 if (!isCloudSave)
                 {
                     Directory.CreateDirectory(text);
                 }
             }
             catch
             {
             }
             text = string.Concat(new object[]
             {
                 text,
                 Path.DirectorySeparatorChar,
                 Main.worldID,
                 ".map"
             });
             Stopwatch stopwatch = new Stopwatch();
             stopwatch.Start();
             bool flag2 = false;
             if (!Main.gameMenu)
             {
                 flag2 = true;
             }
             using (MemoryStream memoryStream = new MemoryStream(4000))
             {
                 using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                 {
                     using (DeflateStream deflateStream = new DeflateStream(memoryStream, 0))
                     {
                         int num = 0;
                         byte[] array = new byte[16384];
                         binaryWriter.Write(Main.curRelease);
                         Main.MapFileMetadata.IncrementAndWrite(binaryWriter);
                         binaryWriter.Write(Main.worldName);
                         binaryWriter.Write(Main.worldID);
                         binaryWriter.Write(Main.maxTilesY);
                         binaryWriter.Write(Main.maxTilesX);
                         binaryWriter.Write(419);
                         binaryWriter.Write(225);
                         binaryWriter.Write(3);
                         binaryWriter.Write(256);
                         binaryWriter.Write(256);
                         binaryWriter.Write(256);
                         byte b = 1;
                         byte b2 = 0;
                         int i;
                         for (i = 0; i < 419; i++)
                         {
                             if (MapHelper.tileOptionCounts[i] != 1)
                             {
                                 b2 |= b;
                             }
                             if (b == 128)
                             {
                                 binaryWriter.Write(b2);
                                 b2 = 0;
                                 b = 1;
                             }
                             else
                             {
                                 b = (byte)(b << 1);
                             }
                         }
                         if (b != 1)
                         {
                             binaryWriter.Write(b2);
                         }
                         i = 0;
                         b = 1;
                         b2 = 0;
                         while (i < 225)
                         {
                             if (MapHelper.wallOptionCounts[i] != 1)
                             {
                                 b2 |= b;
                             }
                             if (b == 128)
                             {
                                 binaryWriter.Write(b2);
                                 b2 = 0;
                                 b = 1;
                             }
//.........这里部分代码省略.........
开发者ID:MEFBAEA,项目名称:mefbaea,代码行数:101,代码来源:MapHelper.cs

示例10: PerformTrialWi8870

        private void PerformTrialWi8870(byte[] buffer)
        {
            TestContext.WriteLine("Original");

            byte[] compressedBytes = null;
            using (MemoryStream ms1 = new MemoryStream())
            {
                using (DeflateStream compressor = new DeflateStream(ms1, CompressionMode.Compress, false))
                {
                    compressor.Write(buffer, 0, buffer.Length);
                }
                compressedBytes = ms1.ToArray();
            }

            TestContext.WriteLine("Compressed {0} bytes into {1} bytes",
                                  buffer.Length, compressedBytes.Length);

            byte[] decompressed= null;
            using (MemoryStream ms2 = new MemoryStream())
            {
                using (var deflateStream = new DeflateStream(ms2, CompressionMode.Decompress, false))
                {
                    deflateStream.Write(compressedBytes, 0, compressedBytes.Length);
                }
                decompressed = ms2.ToArray();
            }

            TestContext.WriteLine("Decompressed");


            bool check = true;
            if (buffer.Length != decompressed.Length)
            {
                TestContext.WriteLine("Different lengths.");
                check = false;
            }
            else
            {
                for (int i=0; i < buffer.Length; i++)
                {
                    if (buffer[i] != decompressed[i])
                    {
                        TestContext.WriteLine("byte {0} differs", i);
                        check = false;
                        break;
                    }
                }
            }

            Assert.IsTrue(check,"Data check failed.");
        }
开发者ID:bedashii,项目名称:ReturnMedz,代码行数:51,代码来源:ZlibUnitTest1.cs

示例11: inflate

        private static void inflate(out byte[] conversionBuffer)
        {
            byte[] bufferin = null;
            foreach (PngTrunk dataTrunk in _trunks)
            {
                if (dataTrunk.getName().Equals("IDAT", StringComparison.OrdinalIgnoreCase))
                {
                    bufferin = dataTrunk.getData();

                }
            }
            var ms = new MemoryStream();
            var deflateStream = new DeflateStream(ms,CompressionMode.Decompress,true);
            if (bufferin != null) deflateStream.Write(bufferin,0,bufferin.Length);
            conversionBuffer = ms.GetBuffer();
        }
开发者ID:kurdtkobain,项目名称:DestifySharp,代码行数:16,代码来源:iPNGConverter.cs


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