SevenZipSharp-压缩内存流 [英] SevenZipSharp - compress memory stream

查看:151
本文介绍了SevenZipSharp-压缩内存流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SevenZipSharp以便将文件压缩为zip文件. 有没有一种方法可以使用它从内存流中创建一个zip文件(意味着,先将文件加载到内存流中)?

I am using SevenZipSharp in order to compress files into a zip file. Is there a way to use it to create a zip from a memory stream (meaning, load the file into the memory stream before)?

谢谢, 玛雅人.

推荐答案

我正在将SevenZipSharp与流结合使用.

I'm using SevenZipSharp with streams no problem what so ever.

SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
compressor.CompressionLevel = SevenZip.CompressionLevel.Normal;
compressor.CompressStream(ms, compressedStream);

在最后一行,"ms"是我要压缩的流,比方说一个MemoryStream. "compressedStream"是我要压缩的流,它可以是另一个MemoryStream甚至是FileStream ...

On the final line, "ms" is a stream that I want to compress, let's say a MemoryStream. "compressedStream" is the stream I want to zip to, it can be either another MemoryStream or even a FileStream...

减压:

SevenZip.SevenZipExtractor extractor = new SevenZip.SevenZipExtractor(compressedStream);
extractor.ExtractFile(0, decompressedStream);

SevenZipExtractor没有解压缩流方法,因此我改用ExtractFile().

The SevenZipExtractor doesn't have a decompress stream method, so I use ExtractFile() instead.

非常容易.在调用上述任何代码之前,我必须使用以下命令指定7zip dll:

Very easy. And before any of the above code is called I must specify the 7zip dll with:

SevenZip.SevenZipBase.SetLibraryPath(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\7-zip\\7z.dll");

就我而言,我没有将7z.dll与我的应用程序捆绑在一起,而是将7-zip单独安装到计算机上.

In my case, I don't bundle the 7z.dll with my app, 7-zip is installed seperately onto the machine.

总之超级简单.我从codeplex- http://sevenzipsharp.codeplex.com/下载了SevenZipSharp,并从 http://www.7-zip.org/.

All in all super easy. I downloaded SevenZipSharp from codeplex - http://sevenzipsharp.codeplex.com/ and 7-zip from http://www.7-zip.org/.

这篇关于SevenZipSharp-压缩内存流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆