根据此链接如何使用.NET创建7-Zip存档?,WOPR告诉我们如何使用7z SDK(http://www.7-zip.org/sdk.html )使用LMZA(7z压缩算法)压缩文件
using SevenZip.Compression.LZMA;
private static void CompressFileLZMA(string inFile, string outFile)
{
SevenZip.Compression.LZMA.Encoder coder = new SevenZip.Compression.LZMA.Encoder();
using (FileStream input = new FileStream(inFile, FileMode.Open))
{
using (FileStream output = new FileStream(outFile, FileMode.Create))
{
coder.Code(input, output, -1, -1, null);
output.Flush();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是如何解压呢?
我尝试:
private static void DecompressFileLZMA(string inFile, string outFile)
{
SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
using (FileStream input = new FileStream(inFile, FileMode.Open))
{
using (FileStream output = new FileStream(outFile, FileMode.Create))
{
coder.Code(input, output, input.Length, …Run Code Online (Sandbox Code Playgroud) 我发现7-zip很棒,我想在.net应用程序上使用它.我有一个10MB的文件(a.001),它需要:

2秒编码.
如果我能在c#上做同样的事情,那将会很好.我已经下载了http://www.7-zip.org/sdk.html LZMA SDK c#源代码.我基本上将CS目录复制到visual studio中的控制台应用程序中:

然后我编译和eveything编译顺利.所以在输出目录中我放置了a.00110MB大小的文件.关于我放置的源代码的主要方法:
[STAThread]
static int Main(string[] args)
{
// e stands for encode
args = "e a.001 output.7z".Split(' '); // added this line for debug
try
{
return Main2(args);
}
catch (Exception e)
{
Console.WriteLine("{0} Caught exception #1.", e);
// throw e;
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行控制台应用程序时,应用程序运行良好,我得到a.7z工作目录上的输出.问题是需要很长时间.执行大约需要15秒!我也试过/sf/answers/614314921/方法,这也需要很长时间.为什么它比实际程序慢10倍?
即使我设置只使用一个线程:

它仍然需要更少的时间(3秒对15):
可能是因为C#比汇编还是C慢?我注意到该算法执行了大量繁重的操作.例如,比较这两个代码块.他们都做同样的事情:
#include <time.h>
#include<stdio.h>
void main()
{
time_t now;
int i,j,k,x;
long …Run Code Online (Sandbox Code Playgroud) 在Windows 8上,我正在运行Windows服务.该服务应该由一个程序启动
Process.Start(exePath);
Run Code Online (Sandbox Code Playgroud)
但是该过程立即退出 - 即使主程序中的第一行也未执行.以前,当在Windows 7上的同一服务中运行相同的进程时,一切正常.
我该如何让它再次运作?如何从Windows服务正确启动进程?
我有一个压缩文件 .rar .7z、.tar 和 .zip,我想重命名上面使用 C# 存档的压缩文件中可用的物理文件名。
我已经使用一个sharpcompress 库尝试过这个,但是我在.rar .7z、.tar 和.zip 文件中找不到这样的重命名文件或文件夹名称的功能。
我也尝试过使用 DotNetZip 库,但它唯一的支持。 Zip 看看我使用 DotNetZip 库尝试过什么。
private static void RenameZipEntries(string file)
{
try
{
int renameCount = 0;
using (ZipFile zip2 = ZipFile.Read(file))
{
foreach (ZipEntry e in zip2.ToList())
{
if (!e.IsDirectory)
{
if (e.FileName.EndsWith(".txt"))
{
var newname = e.FileName.Split('.')[0] + "_new." + e.FileName.Split('.')[1];
e.FileName = newname;
e.Comment = "renamed";
zip2.Save();
renameCount++;
}
}
}
zip2.Comment = String.Format("This archive has been modified. {0} files have been renamed.", …Run Code Online (Sandbox Code Playgroud) 在7-zip没有"确认pwd"字段的日子里,我的密码输入了一个错字.所以现在我有一个受pwd保护的7-zip文件.我写了一些软件来生成我的密码最有可能的拼写错误(5500万)并将其存储在每25k的文件中.现在我一个接一个地尝试它们.我可以使用Macbook上的unar命令行工具在一小时内完成大约25k pwd.
它有效,但它仍然需要100天(24/7)才能通过所有55万个pwds.现在我想知道,如果有一些库(c#mono/dotnet)支持解码受pwd保护的7z文件?
关于解决我的问题的任何其他建议也是受欢迎的.
Is there a .NET library that I can use to sync a folder to S3? I am not interested in full apps or command line tools, just the API. I need to use it from my own app directly.
If there isn't, has anyone written their own, and if so, can you share some of the key considerations when writing one? Anything specific I need to watch out for?
顺便说一下,我将使用它进行备份,这样我就不必每次都压缩整个文件夹并将 zip 文件上传到 S3。我希望以这种方式对非常大的文件夹(例如 SyncBack)执行此操作将花费更短的时间。
我需要在C#中使用7zip.没有控制台,只有7zSharp.dll?+我在这里找到一些数据
http://7zsharp.codeplex.com/releases/view/10305,
但我不知道如何使用它( - 我可以创建.bat(.cmd)文件,但我需要通过dll文件)正好:我需要提取.7z文件与键)
我使用了Marc Gravell在SO中给出的代码来解压缩文件
并在此行中得到此错误 while ((myEntry = s.GetNextEntry()) != null)
ICSharpCode.SharpZipLib.Zip.ZipException: Wrong Local header signature: 0xAFBC7A37
Run Code Online (Sandbox Code Playgroud)
任何建议??
我需要使用SharpCompress将文件压缩为7zip:http://sharpcompress.codeplex.com
我做了如下:
using (var archive = ZipArchive.Create())
{
archive.AddEntry("CompressionTest.pdb", new FileInfo("CompressionTest.pdb"));
using (Stream newStream = File.Create("CompressionTest212.7z"))
{
archive.SaveTo(newStream, SharpCompress.Common.CompressionType.LZMA);
}
}
Run Code Online (Sandbox Code Playgroud)
压缩过程成功完成.但是,无法使用7z(http://www.7-zip.org/download.html)或winrar提取压缩文件.
我不知道是否有人也遇到了同样的问题,并且知道如何解决它?
提前致谢.
c# ×8
7zip ×6
.net ×4
compression ×2
lzma ×2
zip ×2
amazon-s3 ×1
brute-force ×1
open-source ×1
performance ×1
process ×1
rar ×1
sdk ×1
service ×1
tar ×1