7zipsharp extracting/decompressing stream to stream

你离开我真会死。 提交于 2019-12-12 03:26:56

问题


I am using sevenzipsharp library: http://sevenzipsharp.codeplex.com/

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);

I tried with this:

            using (var tmp = new SevenZipExtractor(compressed))
            {
                tmp.ExtractFile(1, File.Create(@"D:\lel.txt"));
            }

回答1:


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.

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.,

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.

The final code should look like this:

            using (var tmp = new SevenZipExtractor((stream_to_compress)))
            {
                tmp.ExtractFile(0,output_stream ));
            }


来源:https://stackoverflow.com/questions/36331557/7zipsharp-extracting-decompressing-stream-to-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!