SevenZipSharp

编程入门 行业动态 更新时间:2024-10-24 06:24:47
本文介绍了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- 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

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

发布评论

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

>www.elefans.com

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