gzipstream.copyto替代简便的方法,在.NET 3.5中

编程入门 行业动态 更新时间:2024-10-25 13:23:37
本文介绍了gzipstream.copyto替代简便的方法,在.NET 3.5中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

喜 在这code。在.NET 4中,我用CopyTo从gzipstream方法

hi in this code in 4 i used copyto method of gzipstream

System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray); GZipStream DecompressOut = new GZipStream(ms, System.IO.Compression.CompressionMode.Decompress); MemoryStream outmem = new MemoryStream(); DecompressOut.copyto(outmem); FileStream outFile = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter m_streamWriter = new StreamWriter(outFile);

我怎么能直接写给写GZipStream到的MemoryStream或者的FileStream?

how can i diretly write GZipStream into MemoryStream or FileStream?

推荐答案

流之间复制是pretty的基础:

Copying between streams is pretty basic:

public static long CopyTo(this Stream source, Stream destination) { byte[] buffer = new byte[2048]; int bytesRead; long totalBytes = 0; while((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0) { destination.Write(buffer, 0, bytesRead); totalBytes += bytesRead; } return totalBytes; }

因此​​,只要插上在,你应该进行排序:

So just plug that in, and you should be sorted:

using(var ms = new MemoryStream(byteArray)) using(var gzip = new GZipStream(ms, CompressionMode.Decompress)) using (var file = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)) { gzip.CopyTo(file); }

更多推荐

gzipstream.copyto替代简便的方法,在.NET 3.5中

本文发布于:2023-11-15 17:26:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596487.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简便   方法   copyto   gzipstream   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!