Been playing with this most of today ... how sad - and still no sucess after going through many posts.
I have 2 main functions 1 to compress a byte [ and return it, and vice-versa to decompress a byte [ and return it.
I think I've setup the compression correctly - but can't test fully without getting the decompression working. Here are the 2 functions:
Please take a peak and let me know what I've missed, thanks in advance ...
public byte[ Compress(byte[ data)
{
byte[ output = null;
MemoryStream str = new MemoryStream();
Crc32 crc = new Crc32();
if (data != null)
{
try
{
using (ZipOutputStream zipstr = new ZipOutputStream(str))
{
string s = Encoding.ASCII.GetString(data);
//ZipEntry entry = new ZipEntry(s);
ZipEntry entry = new ZipEntry("DC_Test");
entry.DateTime = DateTime.Now;
entry.Size = s.Length;
crc.Reset();
crc.Update(data);
entry.Crc = crc.Value;
zipstr.PutNextEntry(entry);
zipstr.Write(data, 0, data.Length);
s = Encoding.ASCII.GetString(str.ToArray());
output = str.ToArray();
zipstr.Finish();
zipstr.Close();
}
}
catch
{
output = null;
}
}
return output;
}
public byte[ Decompress(byte[ data)
{
byte[ output = null;
//string st = new ASCIIEncoding().GetString(data);
//output = Encoding.ASCII.GetBytes(st);
ZipEntry entry;
MemoryStream str = new MemoryStream(data);
str.Seek(0, SeekOrigin.Begin);
if (data != null)
{
try
{
using (ZipInputStream s = new ZipInputStream(str))
{
entry = s.GetNextEntry();
long size = entry.Size;
byte[ buffer = new byte[size];
size = s.Read(buffer, 0, size);
output = buffer;
}
}
catch
{
output = null;
}
}
return output;
}