[英]SevenZipSharp - compress memory stream
I am using SevenZipSharp in order to compress files into a zip file. 我正在使用SevenZipSharp将文件压缩为zip文件。 Is there a way to use it to create a zip from a memory stream (meaning, load the file into the memory stream before)?
有没有办法用它来从内存流创建一个zip(意思是,之前将文件加载到内存流中)?
Thanks, Maya. 谢谢,玛雅。
I'm using SevenZipSharp with streams no problem what so ever. 我正在使用SevenZipSharp与流没有问题。
SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
compressor.CompressionLevel = SevenZip.CompressionLevel.Normal;
compressor.CompressStream(ms, compressedStream);
On the final line, "ms" is a stream that I want to compress, let's say a MemoryStream. 在最后一行,“ms”是我想要压缩的流,比如说一个MemoryStream。 "compressedStream" is the stream I want to zip to, it can be either another MemoryStream or even a FileStream...
“compressedStream”是我要压缩的流,它可以是另一个MemoryStream,甚至是FileStream ......
For decompression: 对于减压:
SevenZip.SevenZipExtractor extractor = new SevenZip.SevenZipExtractor(compressedStream);
extractor.ExtractFile(0, decompressedStream);
The SevenZipExtractor doesn't have a decompress stream method, so I use ExtractFile() instead. SevenZipExtractor没有解压缩流方法,所以我使用ExtractFile()代替。
Very easy. 很容易。 And before any of the above code is called I must specify the 7zip dll with:
在调用上述任何代码之前,我必须使用以下命令指定7zip dll:
SevenZip.SevenZipBase.SetLibraryPath(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\7-zip\\7z.dll");
In my case, I don't bundle the 7z.dll with my app, 7-zip is installed seperately onto the machine. 在我的情况下,我没有将7z.dll与我的应用程序捆绑在一起,7-zip单独安装到机器上。
All in all super easy. 总而言之,超级简单。 I downloaded SevenZipSharp from codeplex - http://sevenzipsharp.codeplex.com/ and 7-zip from http://www.7-zip.org/ .
我从codeplex下载了SevenZipSharp - http://sevenzipsharp.codeplex.com/和http://www.7-zip.org/的 7-zip。
Unfortunately is SevenZipSharp just a COM wrapper around the 7z application. 不幸的是,SevenZipSharp只是围绕7z应用程序的COM包装器。 So there is no easy stream support.
所以没有简单的流支持。 Maybe it is possible to instruct it through
<SevenZipCompressor Instance>.CustomParameters.Add()
to output the file to stdout
, which can then be read in somehow in your application. 也许可以通过
<SevenZipCompressor Instance>.CustomParameters.Add()
来指示它将文件输出到stdout
,然后可以在应用程序中以某种方式读取它。 But this is just speculative and i have no direct tip on how to get this to work. 但这只是推测性的,我没有直接提示如何让它发挥作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.