问题描述
我正在使用sevenzipsharp库: http://sevenzipsharp.codeplex.com/
I am using sevenzipsharp library: http://sevenzipsharp.codeplex.com/
我在巫婆中提出了类似的问题,当时我正在使用线程在同一时间压缩和解压缩流,巫婆i由于意识到这一点已被删除,因此无法完成.但是我的问题仍然存在.我如何解压缩/解压压缩流,而不是解压缩到文件,而是解压缩到另一个流.我在以下位置搜索了sevenzipsharp创建者提供的示例: http://sevenzipsharp.codeplex .com/SourceControl/latest#SevenZipTest/Program.cs ,可悲的是我没有找到有效的示例来证明自己的目标.
I made a similar question in witch i was compressing and decompressing a stream at the "same time" using threads, witch i since have deleted due to realizing that, that cannot be done. However my question still stands. How do i decompress/extract a compressed stream, not to a file, but to another stream. I have searched the examples provided by the sevenzipsharp creators in : http://sevenzipsharp.codeplex.com/SourceControl/latest#SevenZipTest/Program.cs , sadly i have found no valid example to what i am trying to achieve.
我已经用这种方法压缩了流:
I have compressed the stream with this method:
SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra;
compressor.CompressStream(stream,output_compressed);
我尝试过:
using (var tmp = new SevenZipExtractor(compressed))
{
tmp.ExtractFile(1, File.Create(@"D:\lel.txt"));
}
推荐答案
我在编写此问题时找到了解决方案,所以我将自己为可能遇到此问题的其他人回答.
I found the solution while i was writing this question, so i will answer it myself for other people that might come across this problem.
"ExtractFile"需要2个参数,数字1是存档内文件的索引,数字2是输出流或文件.
The 'ExtractFile' is expecting 2 parameters, number 1 is the index of the file inside the archive, number 2 is the output stream or file.,
但是,当声明SevenZipExtractor时,您提供的不是压缩文件,而是像我一样已经在内存中的压缩流,并且只有一个文件,第一个参数(索引)必须为0.
but, when declaring SevenZipExtractor you provide it with not an archive but a compressed stream that is already in memory like i did, and there is nothing but just one file, the 1st parameter(index) must be 0.
最终代码应如下所示:
using (var tmp = new SevenZipExtractor((stream_to_compress)))
{
tmp.ExtractFile(0,output_stream ));
}
这篇关于7zipsharp提取/解压缩流到流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!