GZipStream.Write 方法
我已经阅读了一段时间有关 GZipStream
及其 Write
方法的内容。我试图做的是转换流中的压缩数据并将其放入字节数组中。我将在下面留下我的代码,因为我相信它会有很大帮助。
public static void Compress(byte[] fi)
{
using (MemoryStream inFile = new MemoryStream(fi))
using (FileStream outFile = File.Create(@"C:\Compressed.exe"))
using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress))
{
inFile.CopyTo(Compress);
}
}
我不想写入磁盘上的文件,而是想将压缩数据写入字节数组,然后返回字节数组(当然假设我将其设为函数)。
I have been reading for a short while about GZipStream
and its Write
method. What I am attempting to do is convert the compressed data from the stream and put it in a byte array. I will leave you with my code below as I believe it will help significantly.
public static void Compress(byte[] fi)
{
using (MemoryStream inFile = new MemoryStream(fi))
using (FileStream outFile = File.Create(@"C:\Compressed.exe"))
using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress))
{
inFile.CopyTo(Compress);
}
}
Rather than writing to a file on my disk, I would like to write the compressed data onto a byte array, and then return the byte array (assuming I made this a function of course).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需使用另一个
MemoryStream
及其ToArray
方法。You can simply use use another
MemoryStream
and itsToArray
method.来自我的扩展库之一
From one of my extension libraries