W
wl
Hi all,
I don't know whether is the best place for posting my message, but it just
drives me crazy and didn't find a better newgroup for this.
I'm using the ICSharpCode.SharpZipLib for zipping a string to a compressed
string and the other way around.
But when I do a compress/uncompress on "Wim Lambrechts" I received "Wae
Daebrec`ts", so it seems a single bit in each byte is turned off.
I'm using the following code for compressing a string into a compressed
string
public static string CompressString (string input)
{
MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input));
byte[] buffer = new byte[instream.Length];
instream.Read(buffer, 0, buffer.Length);
instream.Close();
MemoryStream outstream = new MemoryStream();
ZipOutputStream s = new ZipOutputStream(outstream);
s.SetLength(9);
ZipEntry entry = new ZipEntry("");
Crc32 crc = new Crc32();
crc.Reset();
crc.Update(buffer);
entry.Size = buffer.Length;
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
s.Finish();
s.Close();
return (new ASCIIEncoding().GetString(outstream.GetBuffer()));
}
and for uncompressing:
public static string DecompressString2 (string input)
{
MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input));
MemoryStream outstream = new MemoryStream();
ZipInputStream s = new ZipInputStream(instream);
s.GetNextEntry();
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
outstream.Write(data, 0, size);
}
else
{
break;
}
}
return (new ASCIIEncoding().GetString(outstream.GetBuffer()));
}
Again, it drives me crazy: any help is welcome !!!
Wim
I don't know whether is the best place for posting my message, but it just
drives me crazy and didn't find a better newgroup for this.
I'm using the ICSharpCode.SharpZipLib for zipping a string to a compressed
string and the other way around.
But when I do a compress/uncompress on "Wim Lambrechts" I received "Wae
Daebrec`ts", so it seems a single bit in each byte is turned off.
I'm using the following code for compressing a string into a compressed
string
public static string CompressString (string input)
{
MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input));
byte[] buffer = new byte[instream.Length];
instream.Read(buffer, 0, buffer.Length);
instream.Close();
MemoryStream outstream = new MemoryStream();
ZipOutputStream s = new ZipOutputStream(outstream);
s.SetLength(9);
ZipEntry entry = new ZipEntry("");
Crc32 crc = new Crc32();
crc.Reset();
crc.Update(buffer);
entry.Size = buffer.Length;
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
s.Finish();
s.Close();
return (new ASCIIEncoding().GetString(outstream.GetBuffer()));
}
and for uncompressing:
public static string DecompressString2 (string input)
{
MemoryStream instream = new MemoryStream(Encoding.ASCII.GetBytes(input));
MemoryStream outstream = new MemoryStream();
ZipInputStream s = new ZipInputStream(instream);
s.GetNextEntry();
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
outstream.Write(data, 0, size);
}
else
{
break;
}
}
return (new ASCIIEncoding().GetString(outstream.GetBuffer()));
}
Again, it drives me crazy: any help is welcome !!!
Wim