Standard Input/Output Locking Up

  • Thread starter Thread starter _
  • Start date Start date
?

_

Since the .NET framework 1.1 does not come with any built-in
file/stream compression methods, I've had to come up with my own
solution--which is not much of a solution because it doesn't work for
all cases. I don't know why.

It'll work for short input strings, but the problem is when I try and
pass in a particular string of about 16 million characters in length.
It'll lock up on the line 'zp.StandardInput.Write(input)' and just sit
there.

The functionality of 'gzip.exe' is verified. It works just fine on the
command line using standard input/output streams for tested files over
120 million bytes.

Can someone please help me over this hump? Perhaps another approach to
the method's implementation?

Any help or insight would be appreciated.


Jeff



public static byte[] Compress(string input)
{
// get result
//
byte[] result = new byte[0];
using(Process zp = new Process())
{
// setup process
//
zp.StartInfo.Arguments = "-cf";
zp.StartInfo.CreateNoWindow = true;
zp.StartInfo.FileName = @"gzip.exe";
zp.StartInfo.RedirectStandardInput = true;
zp.StartInfo.RedirectStandardOutput = true;
zp.StartInfo.UseShellExecute = false;
zp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
////////////////

// execute process
//
zp.Start();
zp.StandardInput.AutoFlush = true;
zp.StandardInput.Write(input); //locks up here
zp.StandardInput.Close();
//////////////////

// gather results
//
result = UnicodeEncoding.UTF8.GetBytes(
zp.StandardOutput.ReadToEnd());
/////////////////
}
/////////////

// return result
//
return result;
////////////////
}
 
I agree with Ahmed Qurashi's post. Check out SharpZipLib. I am
currently using it in a project at work where I am reading gzip files,
manipulating the data in stream, and then sending them back out to file
as a gzip. The SharpZipLib makes this a snap to do as they have exposed
the functionality as a Stream.

--
Patrick Altman
<><


_ said:
Since the .NET framework 1.1 does not come with any built-in
file/stream compression methods, I've had to come up with my own
solution--which is not much of a solution because it doesn't work for
all cases. I don't know why.

It'll work for short input strings, but the problem is when I try and
pass in a particular string of about 16 million characters in length.
It'll lock up on the line 'zp.StandardInput.Write(input)' and just sit
there.

The functionality of 'gzip.exe' is verified. It works just fine on the
command line using standard input/output streams for tested files over
120 million bytes.

Can someone please help me over this hump? Perhaps another approach to
the method's implementation?

Any help or insight would be appreciated.


Jeff



public static byte[] Compress(string input)
{
// get result
//
byte[] result = new byte[0];
using(Process zp = new Process())
{
// setup process
//
zp.StartInfo.Arguments = "-cf";
zp.StartInfo.CreateNoWindow = true;
zp.StartInfo.FileName = @"gzip.exe";
zp.StartInfo.RedirectStandardInput = true;
zp.StartInfo.RedirectStandardOutput = true;
zp.StartInfo.UseShellExecute = false;
zp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
////////////////

// execute process
//
zp.Start();
zp.StandardInput.AutoFlush = true;
zp.StandardInput.Write(input); //locks up here
zp.StandardInput.Close();
//////////////////

// gather results
//
result = UnicodeEncoding.UTF8.GetBytes(
zp.StandardOutput.ReadToEnd());
/////////////////
}
/////////////

// return result
//
return result;
////////////////
}
 
Thanks for the reply.

I thought about multiple threads, but then the solution would be
non-trivial.

Heh, maybe one day running multiple threads will be non-trivial to me.

Here's to wishing!


Jeff
 
Back
Top