views:

1264

answers:

3

I get the error "Not implemented".

I want to compress a file using 7-Zip via stdin then take the data via stdout and do more conversions with my application. In the man page it shows this example:

% echo foo | 7z a dummy -tgzip -si -so > /dev/null

I am using Windows and C#.

Results:

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

System error:
Not implemented

Code:

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

Is there another simple way to read the file into memory?

Right now I can 1) write to a temporary file and read (easy and can copy/paste some code) 2) use a file pipe (medium? I have never done it) 3) Something else.

A: 

You might need to use 7za.exe, which is the "Commandline version" on the 7z download page. I see that you are currently using 7z.exe, and I'm pretty sure that's a problem I've encountered before as well.


Actually, I think I switched to PeaZip because of the troubles 7z was giving me. PeaZip is a wrapper around 7z and a few other compression utilities, and PeaZip has a little bit better command line interface.

Mark Rushakoff
+1  A: 

You might want to try out something like SevenZipSharp http://www.codeplex.com/sevenzipsharp, I've never used it personally but it provides a wrapper to the 7za.dll COM library which may be helpful to you.

I've written utilities that utilise 7-Zip via a process myself and haven't had issues though I've never tried to do StdIn and StdOut stuff. In the Help files I have with my version of 7-Zip the page on the -si switch states:

Note: The current version of 7-Zip does not support reading of archives from stdin.

Note sure if this might be the source of your problem, with specifying both switches it might be confusing 7-Zip.

The examples they show in the help seem to show that -so is used to redirect the output to standard out but requires normal file based inputs to do so.

RobV
+1  A: 

@ Mark: 7za is the reduced version of 7z (drops the support for some archive types), 7z is the command line version of 7-Zip (supports the same archive types).

Drosophila