So I'm trying to compress an array of bytes (via a Stream). ExtendedStream is just a class I made that interfaces with a base stream (by default MemoryStream). If I take my original data, compress it, decompress it, then compare the size of the decompressed data to the size of the original data (before compression) it turns out that it's smaller than the original.
Original length: 51695, Compressed length: 26014, Decompressed length: 48685.
I'm storing tiles (7 bytes). Compressing using the GZip classes provided in the System.IO.Compression namespace.
public static ExtendedStream GZipDecompress(ExtendedStream stream)
{
ExtendedStream outStream = new ExtendedStream();
GZipStream decompressStream = new GZipStream(stream.BaseStream, CompressionMode.Decompress, true);
int b = -1;
while ((b = decompressStream.ReadByte()) != -1)
{
outStream.WriteByte((Byte)b);
}
outStream.Seek(0, SeekOrigin.Begin);
return outStream;
}
public static ExtendedStream GZipCompress(ExtendedStream stream)
{
ExtendedStream outStream = new ExtendedStream(); // base stream is a memorystream
GZipStream compressStream = new GZipStream(outStream.BaseStream, CompressionMode.Compress, true);
compressStream.Write(stream.ToArray(), 0, (int)stream.Length);
compressStream.Flush();
outStream.Seek(0, SeekOrigin.Begin);
return outStream;
}
Hope that's enough information.