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


C# DeflateStream.Write方法代码示例

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


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

示例1: 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);
				DeflateStream dos = new DeflateStream(ofs, CompressionMode.Compress, true);
				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.Close();
				length = ofs.Length;
			}
			finally
			{
				if(ifs != null) ifs.Close();
				if(ofs != null) ofs.Close();
			}
			return length;
		}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-msnet-netz-compressor-madebits,代码行数:30,代码来源:net20comp.cs

示例2: Deflate

    public static byte[] Deflate(this byte[] data)
    {
        using (MemoryStream output = new MemoryStream())
        {
            using (DeflateStream gzip = new DeflateStream(output, CompressionMode.Compress))
            {
                gzip.Write(data, 0, data.Length);
            }

            return output.ToArray();
        }
    }
开发者ID:darrenshrwd,项目名称:elevated-common,代码行数:12,代码来源:CompresionExtensions.cs

示例3: CompressProfile

 static void CompressProfile(string srcfile, string dstfile)
 {
     try
     {
         Console.WriteLine("Reading source...");
         byte[] x = File.ReadAllBytes(srcfile);
         int usize = x.Length;
         Console.WriteLine("Initializing memory stream...");
         MemoryStream ms = new MemoryStream();
         // write uncompressed size as big endian
         ms.WriteByte((byte)((usize>>24) & 0xFF));
         ms.WriteByte((byte)((usize>>16) & 0xFF));
         ms.WriteByte((byte)((usize>>8) & 0xFF));
         ms.WriteByte((byte)(usize & 0xFF));
         // then, compressed data
         // these two bytes are part of zlib standard, but aren't supported by DeflateStream
         ms.WriteByte(0x78);
         ms.WriteByte(0x9C);
         Console.WriteLine("Compressing data...");
         MemoryStream compData = new MemoryStream();
         DeflateStream ds = new DeflateStream(compData, CompressionMode.Compress);
         ds.Write(x, 0, x.Length);
         ds.Close();
         ms.Write(compData.ToArray(), 0, compData.ToArray().Length);
         // Adler32 checksum as big endian - also not supported by DeflateStream, but required by zlib standard
         int checksum = GetAdler32(x);
         ms.WriteByte((byte)((checksum>>24) & 0xFF));
         ms.WriteByte((byte)((checksum>>16) & 0xFF));
         ms.WriteByte((byte)((checksum>>8) & 0xFF));
         ms.WriteByte((byte)(checksum & 0xFF));
         // start filestream
         Console.WriteLine("Creating file stream...");
         FileStream fs = File.Create(dstfile);
         // write hash
         fs.Write(new SHA1CryptoServiceProvider().ComputeHash(ms.ToArray()), 0, 0x14);
         // write usize + compressed data
         fs.Write(ms.ToArray(), 0, ms.ToArray().Length);
         Console.WriteLine("Compression done.\n" + dstfile);
         fs.Close();
         ms.Close();
         compData.Close();
     }
     catch(Exception ex)
     {
         Console.WriteLine(ex.GetType().Name + " | " + ex.Message);
         Console.Beep();
     }
     return;
 }
开发者ID:Erik-JS,项目名称:Misc-Stuff,代码行数:49,代码来源:ProfileTool.cs

示例4: Compress

    public static byte[] Compress(byte[] data)
    {
        try
        {
            MemoryStream ms = new MemoryStream();
            Stream s = new DeflateStream(ms, CompressionMode.Compress);

            s.Write(data, 0, data.Length);
            s.Close();

            return ms.ToArray();
        }
        catch
        {
            return null;
        }
    }
开发者ID:Siadatian,项目名称:kermanshahchhto.ir,代码行数:17,代码来源:Zipper.cs

示例5: CopyToAsync_Roundtrip_OutputMatchesInput_MemberData

        public static IEnumerable<object[]> CopyToAsync_Roundtrip_OutputMatchesInput_MemberData()
        {
            var rand = new Random();
            foreach (int dataSize in new[] { 1, 1024, 4095, 1024 * 1024 })
            {
                var data = new byte[dataSize];
                rand.NextBytes(data);

                var compressed = new MemoryStream();
                using (var ds = new DeflateStream(compressed, CompressionMode.Compress, leaveOpen: true))
                {
                    ds.Write(data, 0, data.Length);
                }
                byte[] compressedData = compressed.ToArray();

                foreach (int copyBufferSize in new[] { 1, 4096, 80 * 1024 })
                {
                    // Memory source
                    var m = new MemoryStream(compressedData, writable: false);
                    yield return new object[] { data, copyBufferSize, m };

                    // File sources, sync and async
                    foreach (bool useAsync in new[] { true, false })
                    {
                        string path = Path.GetTempFileName();
                        File.WriteAllBytes(path, compressedData);

                        FileOptions options = FileOptions.DeleteOnClose;
                        if (useAsync) options |= FileOptions.Asynchronous;
                        yield return new object[] { data, copyBufferSize, new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, options) };
                    }
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:34,代码来源:DeflateStreamTests.cs

示例6: Roundtrip_Write_ReadByte

        public void Roundtrip_Write_ReadByte()
        {
            byte[] data = new byte[1024 * 10];
            new Random(42).NextBytes(data);

            var compressed = new MemoryStream();
            using (var compressor = new DeflateStream(compressed, CompressionMode.Compress, true))
            {
                compressor.Write(data, 0, data.Length);
            }
            compressed.Position = 0;

            using (var decompressor = new DeflateStream(compressed, CompressionMode.Decompress, true))
            {
                for (int i = 0; i < data.Length; i++)
                    Assert.Equal(data[i], decompressor.ReadByte());
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:DeflateStreamTests.cs

示例7: SequentialReadsOnMemoryStream_Return_SameBytes

        public void SequentialReadsOnMemoryStream_Return_SameBytes()
        {
            byte[] data = new byte[1024 * 10];
            new Random(42).NextBytes(data);

            var compressed = new MemoryStream();
            using (var compressor = new DeflateStream(compressed, CompressionMode.Compress, true))
            {
                for (int i = 0; i < data.Length; i += 1024)
                {
                    compressor.Write(data, i, 1024);
                }
            }
            compressed.Position = 0;

            using (var decompressor = new DeflateStream(compressed, CompressionMode.Decompress, true))
            {
                int i, j;
                byte[] array = new byte[100];
                byte[] array2 = new byte[100];

                // only read in the first 100 bytes
                decompressor.Read(array, 0, array.Length);
                for (i = 0; i < array.Length; i++)
                    Assert.Equal(data[i], array[i]);

                // read in the next 100 bytes and make sure nothing is missing
                decompressor.Read(array2, 0, array2.Length);
                for (j = 0; j < array2.Length; j++)
                    Assert.Equal(data[j], array[j]);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:32,代码来源:DeflateStreamTests.cs

示例8: ReadWriteArgumentValidation

        public void ReadWriteArgumentValidation()
        {
            using (var ds = new DeflateStream(new MemoryStream(), CompressionMode.Compress))
            {
                Assert.Throws<ArgumentNullException>(() => ds.Write(null, 0, 0));
                Assert.Throws<ArgumentOutOfRangeException>(() => ds.Write(new byte[1], -1, 0));
                Assert.Throws<ArgumentOutOfRangeException>(() => ds.Write(new byte[1], 0, -1));
                Assert.Throws<ArgumentException>(() => ds.Write(new byte[1], 0, 2));
                Assert.Throws<ArgumentException>(() => ds.Write(new byte[1], 1, 1));
                Assert.Throws<InvalidOperationException>(() => ds.Read(new byte[1], 0, 1));
                ds.Write(new byte[1], 0, 0);
            }
            using (var ds = new DeflateStream(new MemoryStream(), CompressionMode.Compress))
            {
                Assert.Throws<ArgumentNullException>(() => { ds.WriteAsync(null, 0, 0); });
                Assert.Throws<ArgumentOutOfRangeException>(() => { ds.WriteAsync(new byte[1], -1, 0); });
                Assert.Throws<ArgumentOutOfRangeException>(() => { ds.WriteAsync(new byte[1], 0, -1); });
                Assert.Throws<ArgumentException>(() => { ds.WriteAsync(new byte[1], 0, 2); });
                Assert.Throws<ArgumentException>(() => { ds.WriteAsync(new byte[1], 1, 1); });
                Assert.Throws<InvalidOperationException>(() => { ds.Read(new byte[1], 0, 1); });
            }

            using (var ds = new DeflateStream(new MemoryStream(), CompressionMode.Decompress))
            {
                Assert.Throws<ArgumentNullException>(() => ds.Read(null, 0, 0));
                Assert.Throws<ArgumentOutOfRangeException>(() => ds.Read(new byte[1], -1, 0));
                Assert.Throws<ArgumentOutOfRangeException>(() => ds.Read(new byte[1], 0, -1));
                Assert.Throws<ArgumentException>(() => ds.Read(new byte[1], 0, 2));
                Assert.Throws<ArgumentException>(() => ds.Read(new byte[1], 1, 1));
                Assert.Throws<InvalidOperationException>(() => ds.Write(new byte[1], 0, 1));

                var data = new byte[1] { 42 };
                Assert.Equal(0, ds.Read(data, 0, 0));
                Assert.Equal(42, data[0]);
            }
            using (var ds = new DeflateStream(new MemoryStream(), CompressionMode.Decompress))
            {
                Assert.Throws<ArgumentNullException>(() => { ds.ReadAsync(null, 0, 0); });
                Assert.Throws<ArgumentOutOfRangeException>(() => { ds.ReadAsync(new byte[1], -1, 0); });
                Assert.Throws<ArgumentOutOfRangeException>(() => { ds.ReadAsync(new byte[1], 0, -1); });
                Assert.Throws<ArgumentException>(() => { ds.ReadAsync(new byte[1], 0, 2); });
                Assert.Throws<ArgumentException>(() => { ds.ReadAsync(new byte[1], 1, 1); });
                Assert.Throws<InvalidOperationException>(() => { ds.Write(new byte[1], 0, 1); });
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:45,代码来源:DeflateStreamTests.cs

示例9: Compress

 public void Compress(CompressionType type)
 {
     byte[] bytes = CreateBytesToCompress(type);
     PerfUtils utils = new PerfUtils();
     foreach (var iteration in Benchmark.Iterations)
     {
         string filePath = utils.GetTestFilePath();
         using (FileStream output = File.Create(filePath))
         using (DeflateStream zip = new DeflateStream(output, CompressionMode.Compress))
         using (iteration.StartMeasurement())
         {
             zip.Write(bytes, 0, bytes.Length);
         }
         File.Delete(filePath);
     }
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:16,代码来源:Perf.DeflateStream.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:JohannesRudolph,项目名称:Zlib.Portable,代码行数:51,代码来源:ZlibUnitTest1.cs

示例11: DeflateCompressDecompress

    public static void DeflateCompressDecompress(string filename)
    {
        Console.WriteLine("Test compression and decompression on file {0}", filename);
        FileStream infile;
        try
        {
            // Open the file as a FileStream object.
            infile = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            byte[] buffer = new byte[infile.Length];

            // Read the file to ensure it is readable.
            int count = infile.Read(buffer, 0, buffer.Length);
            if (count != buffer.Length)
            {
                infile.Close();
                Console.WriteLine("Test Failed: Unable to read data from file");
                return;
            }
            infile.Close();

            MemoryStream ms = new MemoryStream();
            // Use the newly created memory stream for the compressed data.
            DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Compress, true);
            Console.WriteLine("Compression");
            compressedzipStream.Write(buffer, 0, buffer.Length);
            // Close the stream.
            compressedzipStream.Close();
            Console.WriteLine("Original size: {0}, Compressed size: {1}", buffer.Length, ms.Length);

            // Reset the memory stream position to begin decompression.
            ms.Position = 0;
            DeflateStream zipStream = new DeflateStream(ms, CompressionMode.Decompress);
            Console.WriteLine("Decompression");
            byte[] decompressedBuffer = new byte[buffer.Length + 100];
            // Use the ReadAllBytesFromStream to read the stream.
            int totalCount = DeflateTest.ReadAllBytesFromStream(zipStream, decompressedBuffer);
            Console.WriteLine("Decompressed {0} bytes", totalCount);

            if (!DeflateTest.CompareData(buffer, buffer.Length, decompressedBuffer, totalCount))
            {
                Console.WriteLine("Error. The two buffers did not compare.");
            }
            zipStream.Close();
        } // end try
        catch (InvalidDataException)
        {
            Console.WriteLine("Error: The file being read contains invalid data.");
        }
        catch (FileNotFoundException)
        {
            Console.WriteLine("Error:The file specified was not found.");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("Error: path is a zero-length string, contains only white space, or contains one or more invalid characters");
        }
        catch (PathTooLongException)
        {
            Console.WriteLine("Error: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.");
        }
        catch (DirectoryNotFoundException)
        {
            Console.WriteLine("Error: The specified path is invalid, such as being on an unmapped drive.");
        }
        catch (IOException)
        {
            Console.WriteLine("Error: An I/O error occurred while opening the file.");
        }
        catch (UnauthorizedAccessException)
        {
            Console.WriteLine("Error: path specified a file that is read-only, the path is a directory, or caller does not have the required permissions.");
        }
        catch (IndexOutOfRangeException)
        {
            Console.WriteLine("Error: You must provide parameters for MyGZIP.");
        }
    }
开发者ID:eandbsoftware,项目名称:MCTS_70_536_AllQuestions,代码行数:77,代码来源:Program.cs

示例12: SerializeStoreData

 private static void SerializeStoreData(SessionStateStoreData item, int initialStreamSize, out byte[] buf, out int length, bool compressionEnabled)
 {
     using (MemoryStream stream = new MemoryStream(initialStreamSize))
     {
         Serialize(item, stream);
         if (compressionEnabled)
         {
             byte[] buffer = stream.GetBuffer();
             int count = (int)stream.Length;
             stream.SetLength(0);
             using (DeflateStream stream2 = new DeflateStream(stream, CompressionMode.Compress, true))
             {
                 stream2.Write(buffer, 0, count);
             }
             stream.WriteByte(0xff);
         }
         buf = stream.GetBuffer();
         length = (int)stream.Length;
     }
 }
开发者ID:wyxy2005,项目名称:bluceNet,代码行数:20,代码来源:SessionProvider.cs

示例13: ResponseData

    public const ResponseDataType DefaultDataType = ResponseDataType.PlainText; //PlainText ZipBinary ZipBase64

    #endregion Fields

    #region Methods

    /// <summary>
    /// 将报表XML数据文本输出到HTTP请求
    /// </summary>
    /// <param name="DataPage"></param>
    /// <param name="DataText"></param>
    /// <param name="DataType"></param>
    public static void ResponseData(System.Web.UI.Page DataPage, ref string DataText, ResponseDataType DataType)
    {
        //报表XML数据的前后不能附加任何其它数据,否则XML数据将不能成功解析,所以调用ClearContent方法清理网页中前面多余的数据
            DataPage.Response.ClearContent();

            if (ResponseDataType.PlainText == DataType)
            {
                // 把xml对象发送给客户端
                //DataPage.Response.ContentType = "text/xml";
                DataPage.Response.Write(DataText);
            }
            else
            {
                //将string数据转换为byte[],以便进行压缩
                System.Text.UTF8Encoding converter = new System.Text.UTF8Encoding();
                byte[] XmlBytes = converter.GetBytes(DataText);

                //在 HTTP 头信息中写入报表数据压缩信息
                DataPage.Response.AppendHeader("gr_zip_type", "deflate");                  //指定压缩方法
                DataPage.Response.AppendHeader("gr_zip_size", XmlBytes.Length.ToString()); //指定数据的原始长度
                DataPage.Response.AppendHeader("gr_zip_encode", converter.HeaderName);     //指定数据的编码方式 utf-8 utf-16 ...

                // 把压缩后的xml数据发送给客户端
                if (ResponseDataType.ZipBinary == DataType)
                {
                    System.IO.Compression.DeflateStream compressedzipStream = new DeflateStream(DataPage.Response.OutputStream, CompressionMode.Compress, true);
                    compressedzipStream.Write(XmlBytes, 0, XmlBytes.Length);
                    compressedzipStream.Close();
                }
                else //ResponseDataType.ZipBase64
                {
                    MemoryStream memStream = new MemoryStream();
                    DeflateStream compressedzipStream = new DeflateStream(memStream, CompressionMode.Compress, true);
                    compressedzipStream.Write(XmlBytes, 0, XmlBytes.Length);
                    compressedzipStream.Close(); //这句很重要,这样数据才能全部写入 MemoryStream

                    // Read bytes from the stream.
                    memStream.Seek(0, SeekOrigin.Begin); // Set the position to the beginning of the stream.
                    int count = (int)memStream.Length;
                    byte[] byteArray = new byte[count];
                    count = memStream.Read(byteArray, 0, count);

                    string Base64Text = Convert.ToBase64String(byteArray);
                    DataPage.Response.Write(Base64Text);
                }
            }

            //报表XML数据的前后不能附加任何其它数据,否则XML数据将不能成功解析,所以调用End方法放弃网页中后面不必要的数据
            DataPage.Response.End();
    }
开发者ID:fuhongliang,项目名称:GraduateProject,代码行数:62,代码来源:ReportData.cs

示例14: writeMesh

	private static void writeMesh(Mesh m) {
		string filepath = folderName + "/" + m.name + ".mesh";
		if (File.Exists(filepath)) {
			File.Delete(filepath);
		}
		MemoryStream ms = new MemoryStream();
		BinaryWriter bw = new BinaryWriter(ms);
		Debug.Log("Write Mesh:" + m.name + " to disk:" + filepath);
		// write length
		bw.Write(m.name.Length);
		// write name
		bw.Write(m.name.ToCharArray());
		// write matrix
		float[] rawData = new float[]{
			1, 0, 0, 0, 
			0, 1, 0, 0, 
			0, 0, 1, 0
		};
		for (int i = 0; i < rawData.Length; i++) {
			bw.Write(rawData[i]);
		}
		// write sub mesh count
		bw.Write(1);
		// write vertex count
		bw.Write(m.vertices.Length);
		Debug.Log("\tVertices:" + m.vertices.Length);
		foreach (Vector3 vert in m.vertices) {
			bw.Write(vert.x);
			bw.Write(vert.y);
			bw.Write(vert.z);
		}
		// write uv0
		bw.Write(m.uv.Length);
		Debug.Log("\tUV0:" + m.uv.Length);
		foreach (Vector2 uv0 in m.uv) {
			bw.Write(uv0.x);
			bw.Write(1 - uv0.y);
		}
		// write uv1
		bw.Write(m.uv2.Length);
		Debug.Log("\tUV1:" + m.uv2.Length);
		foreach (Vector2 uv1 in m.uv2) {
			bw.Write(uv1.x);
			bw.Write(uv1.y);
		}
		Debug.Log("normals:" + m.normals.Length);
		// write normal
		if (normal) {
			bw.Write(m.normals.Length);
			foreach (Vector3 n in m.normals) {
				bw.Write(n.x);
				bw.Write(n.y);
				bw.Write(n.z);
			}
		} else {
			bw.Write(0);
		}
		Debug.Log("tangent:" + m.tangents.Length);
		// write tangent
		if (tangent) {
			bw.Write(m.tangents.Length);
			foreach (Vector3 t in m.tangents) {
				bw.Write(t.x);
				bw.Write(t.y);
				bw.Write(t.z);
			}
		} else {
			bw.Write(0);
		}
		// skeleton weights
		bw.Write(0);
		// skeleton indices
		bw.Write(0);
		// write indices
		bw.Write(m.triangles.Length);
		for (int i = 0; i < m.triangles.Length; i++) {
			bw.Write(m.triangles[i]);
		}
		// bounds
		bw.Write(m.bounds.min.x);
		bw.Write(m.bounds.min.y);
		bw.Write(m.bounds.min.z);
		bw.Write(m.bounds.max.x);
		bw.Write(m.bounds.max.y);
		bw.Write(m.bounds.max.z);
		bw.Close();
		
		int size = ms.GetBuffer().Length;
		MemoryStream compressionBytes = new MemoryStream();
		// write to disk
		DeflateStream compressionStream = new DeflateStream(compressionBytes, CompressionMode.Compress);
		compressionStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
		compressionStream.Close();
		
		FileStream fs = new FileStream(filepath, FileMode.Create);
		BinaryWriter cbw = new BinaryWriter(fs);
		// write compression type
		cbw.Write(3);
		// write original size
		cbw.Write(size);
//.........这里部分代码省略.........
开发者ID:helojo,项目名称:Monkey,代码行数:101,代码来源:LightmapPlugin.cs

示例15: compressSend

        /// <summary>
        /// 
        /// </summary>
        /// <param name="arg"></param>
        public void compressSend(Object arg) {
            // Now send this update off
            UInt32 hdr;
            byte[] hdrbuf;
            streamThread parent = (streamThread)arg;

            Debug.Assert(buf != null);

            try {
                if (buf.Length == -1)
                    buf = parent._mirror.GetRect(x, y, w, h);
            } catch {
                Trace.WriteLine("getRect failed");
                return;
            }
            if (buf == null)
                return;

            outbuf = new MemoryStream();

            int checkSum = 1;
            using (DeflateStream compress = new DeflateStream(outbuf, CompressionMode.Compress
#if USE_IONIC_ZLIB
                , CompressionLevel.BestSpeed /* CompressionLevel.BestCompression */)){
                compress.FlushMode = FlushType.Sync;
#else
                )) { 
#endif           

                hdr = ((UInt32)DesktopMirror._bitmapWidth << 16) + ((UInt32)DesktopMirror._bitmapHeight & 0xFFFF);
                hdrbuf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)hdr));
                compress.Write(hdrbuf, 0, hdrbuf.Length);
                checkSum = Adler32.ComputeChecksum(checkSum, hdrbuf, 0, hdrbuf.Length);

                hdr = ((UInt32)Program.maskX << 16) + ((UInt32)Program.maskY & 0xFFFF);
                hdrbuf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)hdr));
                compress.Write(hdrbuf, 0, hdrbuf.Length);
                checkSum = Adler32.ComputeChecksum(checkSum, hdrbuf, 0, hdrbuf.Length);

                hdr = ((UInt32)Program.maskWidth << 16) + ((UInt32)Program.maskHeight & 0xFFFF);
                hdrbuf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)hdr));
                compress.Write(hdrbuf, 0, hdrbuf.Length);
                checkSum = Adler32.ComputeChecksum(checkSum, hdrbuf, 0, hdrbuf.Length);

                hdr = ((UInt32)x << 16) + ((UInt32)y & 0xFFFF);
                hdrbuf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)hdr));
                compress.Write(hdrbuf, 0, hdrbuf.Length);
                checkSum = Adler32.ComputeChecksum(checkSum, hdrbuf, 0, hdrbuf.Length);

                hdr = ((UInt32)w << 16) + ((UInt32)h & 0xFFFF);
                hdrbuf = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)hdr));
                compress.Write(hdrbuf, 0, hdrbuf.Length);
                checkSum = Adler32.ComputeChecksum(checkSum, hdrbuf, 0, hdrbuf.Length);

                /*
    #if USE_BITMAP_COMPRESS
                byte[] bm = new byte[buf.Length / 4];
                byte[] dt = new byte[buf.Length];
                int bi = 0, di = 0;

                for (int i = 0; i < buf.Length; i += sizeof(UInt32))
                    if (buf.buf[i + 3] == 0)
                        bm[bi++] = 0x00;
                    else {
                        bm[bi++] = 0xFF;
                        dt[di++] = buf.buf[i];
                        dt[di++] = buf.buf[i + 1];
                        dt[di++] = buf.buf[i + 2];
                    }

                compress.Write(bm, 0, bi);
                compress.Write(dt, 0, di);
    #else
                compress.Write(buf.buf, 0, buf.Length);
    #endif
                 */
                compress.Write(buf.buf, 0, buf.Length);
            }

            byte[] compHdr = new byte[] { 0x58, 0x85 };
            
            byte[] compData = outbuf.ToArray();
            
            checkSum = Adler32.ComputeChecksum(checkSum, buf.buf, 0, buf.Length);
            int ncheckSum = IPAddress.HostToNetworkOrder(checkSum);
            // byte[] compCheckSum = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(ncheckSum));
            byte[] compCheckSum = BitConverter.GetBytes(ncheckSum);

            hdr = (UInt32)(compHdr.Length + compData.Length + compCheckSum.Length);
            hdrbuf = BitConverter.GetBytes(hdr);
            // Trace.WriteLine("Size: " + (compData.Length));

            // buf.Dispose();
            // Trying to reduce the memory footprint
            // GC.Collect(0, GCCollectionMode.Optimized);
            // GC.Collect(0, GCCollectionMode.Forced);
//.........这里部分代码省略.........
开发者ID:mobilipia,项目名称:Win7,代码行数:101,代码来源:sendUpdate.cs


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