7zip压缩网络流 [英] 7zip compress network stream

查看:455
本文介绍了7zip压缩网络流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在通过网络发送文件之前对其进行压缩。我认为最好的方法是7zip,因为它是免费和开源的。



我如何使用.zip的7zip? b
$ b

我知道 7zip 是免费的,他们有源代码在c#,但由于某种原因,它是非常慢c#而是为了性能原因调用安装7zip时出现的dll 7z.dll 。所以我能够轻松地编组和调用 7z.dll 中的方法是借助于一个名为:


从流内容创建zip文件,保存到流,提取
一个流,从流读取


与7-Zip不同,DotNetZip设计为使用C#/ .Net。

许多示例(包括流式传输)可在 http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples



另一个选择是使用7-Zip命令行版本(7z.exe),以及从标准输入/输出写入/读取。这将允许您使用7-Zip文件格式,同时保持所有的核心工作在本地代码(虽然可能不会有很大的差异)。



回顾SevenZipSharp:


从0.29版本开始,支持流媒体。


< blockquote>

查看 http:// sevenzipsharp.codeplex.com/SourceControl/changeset/view/59007#364711



您似乎想要此方法:

  public void CompressStream(Stream inStream,Stream outStream)

感谢您考虑这里的表演!我认为太多的人会做你想要避免的:压缩到一个临时文件,然后用临时文件做一些事情。


I will like to compress a file before sending it through the network. I think the best approach is 7zip because it is free and open source.

How I use 7zip with .net?

I know that 7zip is free and that they have the source code in c# but for some reason it is very slow on c# so I rather call the dll 7z.dll that comes when installing 7zip for performance reasons. So the way I am able to eassily marshal and call the methods in 7z.dll is with the help of the library called sevenzipsharp . For example adding that dll to my project will enable me to do:

        // if you installed 7zip 64bit version then make sure you change plataform target
        // like on the picture I showed above!
        SevenZip.SevenZipCompressor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");

        var stream = System.IO.File.OpenRead(@"SomeFileToCompress.txt");
        var outputStream = System.IO.File.Create("Output.7z");

        SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
        compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
        compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra;
        compressor.CompressStream(stream, outputStream);

that's how I use 7zip within c#.

Now my question is:

I will like to send a compressed file over the network. I know I could compress it first then send it. The file is 4GB so I will have to wait a long time for it to compress. I will be wasting a lot of space on hard drive. then I will finally be able to send it. I think that is to complicated. I was wondering how it will be possible to send the file meanwhile it is being compressed.


It seems to be a problem with SevenZipSharp:

解决方案

Have you considered an alternate library - one that doesn't even require 7-Zip to be installed / available?

From the description posted at http://dotnetzip.codeplex.com/ :

creating zip files from stream content, saving to a stream, extracting to a stream, reading from a stream

Unlike 7-Zip, DotNetZip is designed to work with C# / .Net.

Plenty of examples - including streaming, are available at http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples .

Another option is to use the 7-Zip Command Line Version (7z.exe), and write to/read from standard in/out. This would allow you to use the 7-Zip file format, while also keeping all of the core work in native code (though there likely won't be much of a significant difference).

Looking back at SevenZipSharp:

Since the 0.29 release, streaming is supported.

Looking at http://sevenzipsharp.codeplex.com/SourceControl/changeset/view/59007#364711 :

it seems you'd want this method:

public void CompressStream(Stream inStream, Stream outStream)

Thank you for considering performance here! I think way too many people would do exactly what you're trying to avoid: compress to a temp file, then do something with the temp file.

这篇关于7zip压缩网络流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆