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


C# Streams.DeflaterOutputStream类代码示例

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


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

示例1: CloseDeflatorWithNestedUsing

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

            Assert.IsNotNull(tempFile, "No permission to execute this test?");
            if (tempFile != null)
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                using (FileStream diskFile = File.Create(tempFile))
                using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
                using (StreamWriter txtFile = new StreamWriter(deflator))
                {
                    txtFile.Write("Hello");
                    txtFile.Flush();
                }

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

示例2: CompressString

        /// <summary>
        /// Compresses a string.
        /// </summary>
        /// <param name="value">The string to compress.</param>
        /// <returns>The compressed string.</returns>
        public string CompressString(string value)
        {
            // The input value must be non-null
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

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

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

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

示例3: Compress

        public byte[] Compress(byte[] bytData, params int[] ratio)
        {
            int compRatio = 9;
            try
            {
                if (ratio[0] > 0)

                {
                    compRatio = ratio[0];
                }
            }
            catch
            {
                throw;
            }

            try
            {
                var ms = new MemoryStream();
                var defl = new Deflater(compRatio, false);
                Stream s = new DeflaterOutputStream(ms, defl);
                s.Write(bytData, 0, bytData.Length);
                s.Close();
                byte[] compressedData = ms.ToArray();
                 return compressedData;
            }
            catch
            {
                throw;

            }
        }
开发者ID:jojozhuang,项目名称:Study,代码行数:32,代码来源:Wrapper.cs

示例4: Compress

		// netz.compress.ICompress implementation

		public long Compress(string file, string zipFile)
		{
			long length = -1;
			FileStream ifs = null;
			FileStream ofs = null;
			try
			{
				ifs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
				ofs = File.Open(zipFile, FileMode.Create, FileAccess.Write, FileShare.None);
				DeflaterOutputStream dos = new DeflaterOutputStream(ofs, new Deflater(Deflater.BEST_COMPRESSION));
				byte[] buff = new byte[ifs.Length];
				while(true)
				{
					int r = ifs.Read(buff, 0, buff.Length);
					if(r <= 0) break;
					dos.Write(buff, 0, r);
				}
				dos.Flush();
				dos.Finish();
				length = dos.Length;
				dos.Close();
			}
			finally
			{
				if(ifs != null) ifs.Close();
				if(ofs != null) ofs.Close();
			}
			return length;
		}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-msnet-netz-compressor-madebits,代码行数:31,代码来源:defcomp.cs

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

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

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

示例8: Compress

 public static byte[] Compress(byte[] Data)
 {
     MemoryStream ms = new MemoryStream();
     Stream s = new DeflaterOutputStream(ms);
     s.Write(Data, 0, Data.Length);
     s.Close();
     return ms.ToArray();
 }
开发者ID:remixod,项目名称:NetLibClient,代码行数:8,代码来源:Compression.cs

示例9: Deflate

 internal static byte[] Deflate(byte[] buffer)
 {
     MemoryStream compressedBufferStream = new MemoryStream();
     DeflaterOutputStream deflaterStream = new DeflaterOutputStream(compressedBufferStream);
     deflaterStream.Write(buffer, 0, buffer.Length);
     deflaterStream.Close();
     return compressedBufferStream.ToArray();
 }
开发者ID:kkkkyue,项目名称:FtexTool,代码行数:8,代码来源:ZipUtility.cs

示例10: ZlibOutputStreamIs

 public ZlibOutputStreamIs(Stream st, int compressLevel, EDeflateCompressStrategy strat, bool leaveOpen)
     : base(st,compressLevel,strat,leaveOpen)
 {
     deflater=new Deflater(compressLevel);
     setStrat(strat);
     ost = new DeflaterOutputStream(st, deflater);
     ost.IsStreamOwner = !leaveOpen;
 }
开发者ID:NoobsArePeople2,项目名称:pngcs,代码行数:8,代码来源:ZlibOutputStreamIs.cs

示例11: Compress

 public static byte[] Compress(byte[] bytes)
 {
     MemoryStream memory = new MemoryStream();
     DeflaterOutputStream stream = new DeflaterOutputStream(memory, new Deflater(Deflater.BEST_COMPRESSION), 131072);
     stream.Write(bytes, 0, bytes.Length);
     stream.Close();
     return memory.ToArray();
 }
开发者ID:mex868,项目名称:Nissi.Solution,代码行数:8,代码来源:Zip.cs

示例12: CompressZlib

 public static byte[] CompressZlib(byte[] input)
 {
     MemoryStream m = new MemoryStream();
     DeflaterOutputStream zipStream = new DeflaterOutputStream(m, new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(8));
     zipStream.Write(input, 0, input.Length);
     zipStream.Finish();
     return m.ToArray();
 }
开发者ID:zeroKilo,项目名称:Zlibber,代码行数:8,代码来源:Form1.cs

示例13: Compress

 public byte[] Compress( byte[] bytes )
 {
     MemoryStream memory = new MemoryStream();
     Stream stream = new DeflaterOutputStream( memory,
         new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(
         ICSharpCode.SharpZipLib.Zip.Compression.Deflater.BEST_COMPRESSION ), 131072 );
     stream.Write( bytes, 0, bytes.Length );
     stream.Close();
     return memory.ToArray();
 }
开发者ID:popovegor,项目名称:gt,代码行数:10,代码来源:GTCommonWebPage.cs

示例14: Encode

        public override byte[] Encode(byte[] data)
        {
            var o = new MemoryStream();

            var compressed = new DeflaterOutputStream(o, new Deflater(1));
            compressed.Write(data, 0, data.Length);
            compressed.Flush();
            compressed.Close();

            return o.ToArray();
        }
开发者ID:ademar,项目名称:melon-reports,代码行数:11,代码来源:FlateFilter.cs

示例15: Compress

        public string Compress(string uncompressedString)
        {
            var stringAsBytes = Encoding.UTF8.GetBytes(uncompressedString);
            var ms = new MemoryStream();
            var outputStream = new DeflaterOutputStream(ms);
            outputStream.Write(stringAsBytes, 0, stringAsBytes.Length);
            outputStream.Close();
            var compressedData = ms.ToArray();

            return Convert.ToBase64String(compressedData, 0, compressedData.Length);
        }
开发者ID:benaston,项目名称:NCacheFacade,代码行数:11,代码来源:SharpZipStringCompressor.cs


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