?
_
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;
////////////////
}
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;
////////////////
}