无法使用 7-Zip 压缩标准输入并使用标准输出输出?

6 c# stdin stdout 7zip

我收到错误“未实施”。

我想通过 stdin 使用7-Zip压缩文件,然后通过 stdout 获取数据并使用我的应用程序进行更多转换。在手册页中显示了这个示例:

% 回声 foo | 7z 虚拟-tgzip -si -so > /dev/null

我正在使用 Windows 和 C#。

结果:

7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03
Creating archive StdOut

System error:
Not implemented
Run Code Online (Sandbox Code Playgroud)

代码:

public static byte[] a7zipBuf(byte[] b)
{
    string line;
    var p = new Process();
    line = string.Format("a dummy -t7z -si -so ");
    p.StartInfo.Arguments = line;
    p.StartInfo.FileName = @"C:\Program Files\7-Zip\7z.exe";
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.RedirectStandardInput = true;

    p.Start();

    p.StandardInput.BaseStream.Write(b, 0, b.Length);
    p.StandardInput.Close();
    Console.Write(p.StandardError.ReadToEnd());
    //Console.Write(p.StandardOutput.ReadToEnd());

    return p.StandardOutput.BaseStream.ReadFully();
}
Run Code Online (Sandbox Code Playgroud)

还有另一种简单的方法将文件读入内存吗?

现在我可以1)写入临时文件并读取(简单并且可以复制/粘贴一些代码)2)使用文件管道(中?我从来没有这样做过)3)其他东西。

Rob*_*obV 4

您可能想尝试诸如 SevenZipSharp http://www.codeplex.com/sevenzipsharp之类的东西,我个人从未使用过它,但它提供了 7za.dll COM 库的包装器,这可能对您有帮助。

我自己编写了通过进程使用 7-Zip 的实用程序,尽管我从未尝试过执行 StdIn 和 StdOut 操作,但没有遇到任何问题。在我的 7-Zip 版本的帮助文件中,-si 开关上的页面指出:

注意:当前版本的 7-Zip 不支持从 stdin 读取档案。

请注意,确定这是否可能是问题的根源,指定这两个开关可能会使 7-Zip 感到困惑。

他们在帮助中显示的示例似乎表明 -so 用于将输出重定向到标准输出,但需要基于普通文件的输入才能执行此操作。