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


C# DeflaterOutputStream.Write方法代码示例

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


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

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

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

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

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

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

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

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

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

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

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

示例11: Compress

 /// <summary>
 /// Compress the specified data.
 /// </summary>
 /// <param name='data'>
 /// Data.
 /// </param>
 static string Compress(byte[] data)
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms);
     DeflaterOutputStream zs = new DeflaterOutputStream(ms);
     bw.Write(data.Length);
     zs.Write(data,0,data.Length);
     zs.Flush();
     zs.Close ();
     bw.Close();
     return "ZipStream:" + Convert.ToBase64String(ms.GetBuffer());
 }
开发者ID:zombiepaladin,项目名称:CI-Team,代码行数:18,代码来源:BS.cs

示例12: Compress

        /// <summary>
        /// Compress an array of bytes.
        /// </summary>
        /// <param name="_pBytes">An array of bytes to be compressed.</param>
        /// <returns>Compressed bytes.</returns>
        /// <example>
        /// Following example demonstrates the way of compressing an ASCII string text.
        /// <code>
        /// public void Compress()
        /// {
        ///     string source = "Hello, world!";
        ///     byte[] source_bytes = System.Text.Encoding.ASCII.GetBytes(source);
        ///     byte[] compressed = DataCompression.Compress(source_bytes);
        ///     
        ///     // Process the compressed bytes here.
        /// }
        /// </code>
        /// </example>
        /// <remarks>It is the best practice that use the overrided <b>DataCompression.Compress</b> method with <see cref="System.String"/> parameter to compress a string.</remarks>
        public static byte[] Compress(byte[] _pBytes)
        {
            MemoryStream ms = new MemoryStream();

            Deflater mDeflater = new Deflater(Deflater.BEST_COMPRESSION);
            DeflaterOutputStream outputStream = new DeflaterOutputStream(ms, mDeflater, 131072);

            outputStream.Write(_pBytes, 0, _pBytes.Length);
            outputStream.Close();

            return ms.ToArray();
        }
开发者ID:daxnet,项目名称:guluwin,代码行数:31,代码来源:DataCompression.cs

示例13: Deflate

		internal static Byte[] Deflate(Byte[] b)
		{
			System.IO.MemoryStream ms = new System.IO.MemoryStream();
			DeflaterOutputStream outStream =new DeflaterOutputStream( ms);
			
			outStream.Write(b, 0, b.Length);
			outStream.Flush();
			outStream.Finish();
			
			Byte[] result=ms.ToArray();
			outStream.Close();
			ms.Close();
			return result;
		}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:14,代码来源:Utility.cs

示例14: Compress

        public static byte[] Compress(byte[] data)
        {
            byte[] result = null;

            using (MemoryStream ms = new MemoryStream())
                using (Stream s = new DeflaterOutputStream(ms))
                {
                    s.Write(data, 0, data.Length);
                    s.Close();
                    result = ms.ToArray();
                }

            return result;
        }
开发者ID:hollow87,项目名称:Arca4,代码行数:14,代码来源:ZipLib.cs

示例15: Serialize

        public static void Serialize(Stream stream, PiaFile piaFile)
        {
            if (stream == null)
                throw new ArgumentNullException("Stream");

            if (piaFile == null)
                throw new ArgumentNullException("PiaFile");

            try
            {
                // Header
                var headerString = piaFile.Header.ToString();
                var headerBytes = Encoding.Default.GetBytes(headerString);
                stream.Write(headerBytes, 0, headerBytes.Length);

                // Nodes
                var nodeString = _serializeNode(piaFile);
                var nodeBytes = Encoding.Default.GetBytes(nodeString);

                // Deflation
                byte[] deflatedBytes;
                var deflater = new Deflater(Deflater.DEFAULT_COMPRESSION);
                using (var ms = new MemoryStream())
                {
                    var deflateStream = new DeflaterOutputStream(ms, deflater);
                    deflateStream.Write(nodeBytes, 0, nodeBytes.Length);
                    deflateStream.Finish();

                    deflatedBytes = ms.ToArray();
                }

                // Checksum
                var checkSum = new byte[12];
                BitConverter.GetBytes(deflater.Adler).CopyTo(checkSum, 0); // Adler
                BitConverter.GetBytes(nodeBytes.Length).CopyTo(checkSum, 4); // InflatedSize
                BitConverter.GetBytes(deflatedBytes.Length).CopyTo(checkSum, 8); // DeflatedSize
                stream.Write(checkSum, 0, checkSum.Length);

                // Final write
                stream.Write(deflatedBytes, 0, deflatedBytes.Length);
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:phusband,项目名称:PiaNO,代码行数:46,代码来源:PiaSerializer.cs


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