7zip的压缩网络流 [英] 7zip compress network stream
问题描述
我会想通过网络发送之前压缩文件。我认为最好的办法是7zip的,因为它是免费和开源的。
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.
如何我用7zip的使用.NET?
我知道 7zip的
是免费的,他们在C#源代码,但由于某种原因,它是C#的速度很慢,所以我而要求性能原因安装7zip的时候自带的DLL 7z.dll
。所以,我能够eassily元帅并调用 7z.dll
方法的方法是使用图书馆的帮助下叫的 sevenzipsharp 。例如添加该DLL到我的项目将使我做的:
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);
这就是我使用C#中7zip的。
that's how I use 7zip within c#.
现在的问题是:
我会想通过网络发送一个压缩文件。我知道我可以先进行压缩然后发送。该文件是4GB,所以我将不得不等待很长的时间才能压缩。我将硬盘上浪费了大量的空间。然后,我将最终能够发送。我认为这是复杂的。 我不知道怎么会可以发送同时它被压缩的文件。
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.
推荐答案
你有没有考虑备选库 - 一个甚至不要求的7-Zip进行安装?/可用
Have you considered an alternate library - one that doesn't even require 7-Zip to be installed / available?
这张贴在 HTTP说明:// dotnetzip .codeplex.com / :
从流内容创建zip文件,保存到一个流,提取
到流,从流中读取
creating zip files from stream content, saving to a stream, extracting to a stream, reading from a stream
与7-ZIP,DotNetZip旨在与C#的工作/ .NET。
Unlike 7-Zip, DotNetZip is designed to work with C# / .Net.
丰盛 - 包括流媒体,可在的 http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples 。
Plenty of examples - including streaming, are available at http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples .
另一种选择是使用7-ZIP命令行版本(7z.exe),并写入到/从/输出标准读取。这将允许您使用7-Zip文件格式,同时保留所有的核心工作的本地代码(虽然有可能不会有太大的差异显著的)。
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).
在SevenZipSharp回首:
Looking back at SevenZipSharp:
自0.29版本,流媒体支持
Since the 0.29 release, streaming is supported.
看着的http:// sevenzipsharp.codeplex.com/SourceControl/changeset/view/59007#364711 :
似乎你想要这个方法:
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屋!