[Mono-dev] Status of System.IO.Compression (both Deflate and Gzip)
David Wolinsky
davidiw at ufl.edu
Mon Jul 23 16:13:51 EDT 2007
I am not having luck with either class using 1.2.4, they both compile
but the results never come out right... perhaps they aren't fully
implemented yet?
Here's what I'm using...
using System;
using System.IO.Compression;
using System.IO;
using System.Security.Cryptography;
namespace poop {
public class poopie {
public static void Main() {
byte [] data = new byte[100000];
for (int i = 0; i < 100000; i++) {
data[i] = (byte) i;
}
MemoryStream dataStream = new MemoryStream (data);
MemoryStream backing = new MemoryStream ();
GZipStream compressing = new GZipStream (backing,
CompressionMode.Compress, true);
CopyStream (dataStream, compressing);
dataStream.Close();
// This next method causes an exception and if uncommented still it
doesn't work right...
compressing.Close();
backing.Seek (0, SeekOrigin.Begin);
GZipStream decompressing = new GZipStream (backing,
CompressionMode.Decompress);
MemoryStream output = new MemoryStream ();
CopyStream (decompressing, output);
Console.WriteLine(backing.Length);
for (int i = 0; i < backing.Length; i++) {
Console.WriteLine(backing.GetBuffer()[i]);
}
Console.WriteLine(compare_buffers (data, output.GetBuffer(), (int)
data.Length));
decompressing.Close();
output.Close();
}
private static void CopyStream (Stream src, Stream dest)
{
byte[] array = new byte[1024];
int bytes_read;
bytes_read = src.Read (array, 0, 1024);
while (bytes_read != 0) {
dest.Write (array, 0, bytes_read);
bytes_read = src.Read (array, 0, 1024);
}
}
private static bool compare_buffers (byte[] first, byte[] second,
int length)
{
if (first.Length < length || second.Length < length) {
return false;
}
for (int i = 0; i < length; i++) {
if (first[i] != second[i]) {
return false;
}
}
return true;
}
}
}
More information about the Mono-devel-list
mailing list