我正在使用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- sevenzipsharp.codeplex/下载了SevenZipSharp,并从 www.7-zip/.
All in all super easy. I downloaded SevenZipSharp from codeplex - sevenzipsharp.codeplex/ and 7-zip from www.7-zip/.
更多推荐
SevenZipSharp
发布评论