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


C# DeflaterOutputStream.Flush方法代码示例

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


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

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

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

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

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

示例5: Compress

        /*
         * Name function: Compress
         * Purpose: compress a part of the byte array into a Zlib Block
         * Input: - buffer: byte array
         *        - offset: starting offset inside the array
         *        - count: num of bytes to compress starting from the offset
         * Output: compressed byte array block, the structure is:
         *         - magic word
         *         - max segment size
         *         - total compressed size
         *         - total uncompressed size
         *         - segment list
         *         - compressed data list
         */
        public static byte[] Compress(byte[] buffer, int offset, int count)
        {
            if(buffer == null)
                throw new ArgumentNullException();
            if (count < 0)
                throw new FormatException();
            if (offset + count > buffer.Length)
                throw new IndexOutOfRangeException();

            MemoryStream headBlock = new MemoryStream();
            MemoryStream dataBlock = new MemoryStream();
            DeflaterOutputStream zipStream;

            int numSeg = (int)Math.Ceiling((double)count / (double)maxSegmentSize);

            headBlock.WriteValueU32(magic);
            headBlock.WriteValueU32(maxSegmentSize);
            headBlock.WriteValueU32(0x0);            //total compressed size, still to calculate
            headBlock.WriteValueS32(count);          //total uncompressed size

            for (int i = count; i > 0; i -= (int)maxSegmentSize)
            {
                int copyBytes = Math.Min(i, (int)maxSegmentSize);
                uint precCompSize = (uint)dataBlock.Length;
                zipStream = new DeflaterOutputStream(dataBlock);
                zipStream.Write(buffer, offset + (count - i), copyBytes);
                zipStream.Flush();
                zipStream.Finish();
                headBlock.WriteValueU32((uint)dataBlock.Length - precCompSize); //compressed segment size
                headBlock.WriteValueS32(copyBytes); //uncompressed segment size
                //Console.WriteLine("  Segment size: {0}, total read: {1}, compr size: {2}", maxSegmentSize, copyBytes, (uint)dataBlock.Length - precCompSize);
            }

            headBlock.Seek(8, SeekOrigin.Begin);
            headBlock.WriteValueS32((int)dataBlock.Length); // total compressed size

            byte[] finalBlock = new byte[headBlock.Length + dataBlock.Length];
            Buffer.BlockCopy(headBlock.ToArray(), 0, finalBlock, 0, (int)headBlock.Length);
            Buffer.BlockCopy(dataBlock.ToArray(), 0, finalBlock, (int)headBlock.Length, (int)dataBlock.Length);
            headBlock.Close();
            dataBlock.Close();

            return finalBlock;
        }
开发者ID:CreeperLava,项目名称:ME3Explorer,代码行数:58,代码来源:ZlibBlock.cs

示例6: Compress

    public static string Compress(byte[] data)
    {
        using(var m = new MemoryStream())
        {
            switch(technique)
            {
            case "ZipStream":

                var br = new BinaryWriter(m);
                var z = new DeflaterOutputStream(m);
                br.Write(data.Length);
                z.Write(data, 0, data.Length);
                z.Flush();
                z.Close();
                break;
            }
            return technique + ":" + Convert.ToBase64String(m.GetBuffer());
        }
    }
开发者ID:Bloodcoder,项目名称:unityserializer-ng,代码行数:19,代码来源:SevenZipHelper.cs

示例7: Compress

	public static string Compress(byte[] data, ICodeProgress progress)
	{
		using(var m = new MemoryStream())
		{
			switch(technique)
			{
			case "ZipStream":
				
				var br = new BinaryWriter(m);
				var z = new DeflaterOutputStream(m);
				br.Write(data.Length);
				z.Write(data, 0, data.Length);
				z.Flush();
				z.Close();
				break;
			case "7Zip":
			default:
				return Convert.ToBase64String(SevenZipRadical.Compression.LZMA.SevenZipRadicalHelper.Compress(data, progress));
			}
			return technique + ":" + Convert.ToBase64String(m.GetBuffer());
		}
	}
开发者ID:MHaubenstock,项目名称:RPG-Board-3D,代码行数:22,代码来源:SevenZipHelper.cs

示例8: Compress

 public static string Compress(byte[] data)
 {
     string result;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         string text = CompressionHelper.technique;
         if (text != null)
         {
             if (CompressionHelper.<>f__switch$map1F == null)
             {
                 CompressionHelper.<>f__switch$map1F = new Dictionary<string, int>(1)
                 {
                     {
                         "ZipStream",
                         0
                     }
                 };
             }
             int num;
             if (CompressionHelper.<>f__switch$map1F.TryGetValue(text, out num))
             {
                 if (num == 0)
                 {
                     BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
                     DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(memoryStream);
                     binaryWriter.Write(data.Length);
                     deflaterOutputStream.Write(data, 0, data.Length);
                     deflaterOutputStream.Flush();
                     deflaterOutputStream.Close();
                 }
             }
         }
         result = CompressionHelper.technique + ":" + Convert.ToBase64String(memoryStream.GetBuffer());
     }
     return result;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:36,代码来源:CompressionHelper.cs

示例9: Compress

        public static byte[] Compress( byte []b, int offset, int len )
        {
            try
            {
                /*zLib e = new zLib();
                byte []compressedData = null;
                e.CompressStream( b, ref compressedData );*/

                MemoryStream ms = new MemoryStream();
                DeflaterOutputStream defl = new DeflaterOutputStream( ms );

                defl.Write(b, offset, len );
                defl.Flush();
                defl.Close();
                byte[] compressedData = (byte[])ms.ToArray();
                //HexViewer.View( compressedData, 0, compressedData.Length );
                return compressedData;
            }
            catch(Exception e)
            {
                Console.WriteLine( e.Message );
                return null;
            }
        }
开发者ID:karliky,项目名称:wowwow,代码行数:24,代码来源:Zip.cs

示例10: GzipFrame

		/// <summary>
		/// deflates (zlib) a VideoCopy, returning a byte array suitable for insertion into a JMD file
		/// the byte array includes width and height dimensions at the beginning
		/// this is run asynchronously for speedup, as compressing can be slow
		/// </summary>
		/// <param name="v">video frame to compress</param>
		/// <returns>zlib compressed frame, with width and height prepended</returns>
		byte[] GzipFrame(VideoCopy v)
		{
			MemoryStream m = new MemoryStream();
			// write frame height and width first
			m.WriteByte((byte)(v.BufferWidth >> 8));
			m.WriteByte((byte)(v.BufferWidth & 255));
			m.WriteByte((byte)(v.BufferHeight >> 8));
			m.WriteByte((byte)(v.BufferHeight & 255));
			var g = new DeflaterOutputStream(m, new Deflater(token.compressionlevel));
			g.IsStreamOwner = false; // leave memory stream open so we can pick its contents
			g.Write(v.VideoBuffer, 0, v.VideoBuffer.Length);
			g.Flush();
			g.Close();
			byte[] ret = m.GetBuffer();
			Array.Resize(ref ret, (int)m.Length);
			m.Close();
			return ret;
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:25,代码来源:JMDWriter.cs

示例11: Deflate

		MemoryStream Deflate(byte[] data, int level, bool zlib)
		{
			MemoryStream memoryStream = new MemoryStream();
			
			Deflater deflater = new Deflater(level, !zlib);
			using ( DeflaterOutputStream outStream = new DeflaterOutputStream(memoryStream, deflater) )
			{
				outStream.IsStreamOwner = false;
				outStream.Write(data, 0, data.Length);
				outStream.Flush();
				outStream.Finish();
			}
			return memoryStream;
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:14,代码来源:InflaterDeflaterTests.cs

示例12: Deflate

        public static int Deflate(byte[] inBuffer, ref byte[] outBuffer)
        {
            int newLen = 0, flagOffset = 1;

            outBuffer[0] = inBuffer[0];
            if (inBuffer[0] == 0)
            {
                flagOffset = 2;
                outBuffer[1] = inBuffer[1];
            }

            if (inBuffer.Length > 30)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, false);
                    using (DeflaterOutputStream outStream = new DeflaterOutputStream(ms, deflater))
                    {
                        outStream.IsStreamOwner = false;
                        outStream.Write(inBuffer, flagOffset, inBuffer.Length - flagOffset);
                        outStream.Flush();
                        outStream.Finish();
                    }

                    ms.Position = 0;
                    ms.Read(outBuffer, flagOffset + 1, (int)ms.Length);
                    newLen = (int)ms.Length + flagOffset + 1;
                    outBuffer[flagOffset] = 0x5a;
                }
            }
            else
            {
                Buffer.BlockCopy(inBuffer, flagOffset, outBuffer, flagOffset + 1, inBuffer.Length - flagOffset);
                outBuffer[flagOffset] = 0xa5;
                newLen = inBuffer.Length + 1;
            }

            return newLen;
        }
开发者ID:natedahl32,项目名称:EqEmulator-net,代码行数:39,代码来源:EQRawApplicationPacket.cs

示例13: WriteDataChunks

        private static void WriteDataChunks()
        {
            byte[] pixels = _image.ToByteArray();

            byte[] data = new byte[_image.PixelWidth * _image.PixelHeight * 4 + _image.PixelHeight];

            int rowLength = _image.PixelWidth * 4 + 1;

            for (int y = 0; y < _image.PixelHeight; y++)
            {
                byte compression = 0;
                if (y > 0)
                {
                    compression = 2;
                }
                data[y * rowLength] = compression;

                for (int x = 0; x < _image.PixelWidth; x++)
                {
                    // Calculate the offset for the new array.
                    int dataOffset = y * rowLength + x * 4 + 1;

                    // Calculate the offset for the original pixel array.
                    int pixelOffset = (y * _image.PixelWidth + x) * 4;

                    data[dataOffset + 0] = pixels[pixelOffset + 0];
                    data[dataOffset + 1] = pixels[pixelOffset + 1];
                    data[dataOffset + 2] = pixels[pixelOffset + 2];
                    data[dataOffset + 3] = pixels[pixelOffset + 3];

                    if (y > 0)
                    {
                        int lastOffset = ((y - 1) * _image.PixelWidth + x) * 4;

                        data[dataOffset + 0] -= pixels[lastOffset + 0];
                        data[dataOffset + 1] -= pixels[lastOffset + 1];
                        data[dataOffset + 2] -= pixels[lastOffset + 2];
                        data[dataOffset + 3] -= pixels[lastOffset + 3];
                    }
                }
            }

            byte[] buffer = null;
            int bufferLength = 0;

            MemoryStream memoryStream = null;
            try
            {
                memoryStream = new MemoryStream();

                using (DeflaterOutputStream zStream = new DeflaterOutputStream(memoryStream))
                {
                    zStream.Write(data, 0, data.Length);
                    zStream.Flush();
                    zStream.Finish();

                    bufferLength = (int)memoryStream.Length;
                    buffer = memoryStream.GetBuffer();
                }
            }
            finally
            {
                if (memoryStream != null)
                {
                    memoryStream.Dispose();
                }
            }

            int numChunks = bufferLength / MaxBlockSize;

            if (bufferLength % MaxBlockSize != 0)
            {
                numChunks++;
            }

            for (int i = 0; i < numChunks; i++)
            {
                int length = bufferLength - i * MaxBlockSize;

                if (length > MaxBlockSize)
                {
                    length = MaxBlockSize;
                }

                WriteChunk(PngChunkTypes.Data, buffer, i * MaxBlockSize, length);
            }
        }
开发者ID:camradal,项目名称:OnThisDayApp,代码行数:87,代码来源:PngWriter.cs

示例14: getOutputByCompress

        private static byte[] getOutputByCompress(byte[] toByteArray) {
            int unCompressedLength = 0;
            int compressedLength = 0;

            byte[] input = toByteArray;
            unCompressedLength = input.Length;

            MemoryStream memoryStream = new MemoryStream();
            Deflater compressor = new Deflater();
            DeflaterOutputStream defos = new DeflaterOutputStream(memoryStream, compressor);
            defos.Write(input, 0, input.Length);
            defos.Flush();
            defos.Finish();
            byte[] output = memoryStream.ToArray();
            compressedLength = output.Length;

            memoryStream.Close();
            defos.Close();

            //set compress flag and compressedLength, unCompressedLength
            byte[] sendData = new byte[output.Length + TransferUtil.getLengthOfByte() + TransferUtil.getLengthOfInt() + TransferUtil.getLengthOfInt()];
            sendData[0] = TransferObject.COMPRESS_FLAG; //0:normal; 1:compress
            TransferOutputStream fos = new TransferOutputStream(sendData);
            fos.skipAByte();
            fos.writeInt(unCompressedLength);
            fos.writeInt(compressedLength);
            Array.Copy(output, 0, sendData, TransferUtil.getLengthOfByte() + TransferUtil.getLengthOfInt() + TransferUtil.getLengthOfInt(), output.Length);

            return sendData;
        }
开发者ID:jxqlovejava,项目名称:Tatala-RPC,代码行数:30,代码来源:TransferUtil.cs

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


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