You can use a dataset as a simple database in your application. To save storage space, you can compress it.

In this tutorial, I'll show you how to compress and decompress a dataset from a stream. You can use System.IO.Compression library to compress and decompress services for streams.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.IO.Compression;

namespace FoxLearn
    public class CompressionObjectDataSet
        public byte[] Compress(DataSet ds)
            MemoryStream ms = new MemoryStream();
            byte[] inbyt = ms.ToArray();
            System.IO.MemoryStream objStream = new MemoryStream();
            System.IO.Compression.DeflateStream objZS = new System.IO.Compression.DeflateStream(objStream, System.IO.Compression.CompressionMode.Compress);
            objZS.Write(inbyt, 0, inbyt.Length);
            return objStream.ToArray();

        public Database Decompress(byte[] bytDs)
            Database outDs = new Database();
            MemoryStream inMs = new MemoryStream(bytDs);
            inMs.Seek(0, 0);
            DeflateStream zipStream = new DeflateStream(inMs, CompressionMode.Decompress, true);
            byte[] outByt = ReadFullStream(zipStream);
            MemoryStream outMs = new MemoryStream(outByt);
            return outDs;

        private byte[] ReadFullStream(Stream stream)
            byte[] buffer = new byte[32768];
                using (MemoryStream ms = new MemoryStream())
                    while (true)
                        int read = stream.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                            return ms.ToArray();
                        ms.Write(buffer, 0, read);
            catch (Exception ex)
                throw ex;

To compress a dataset, you can write your data from dataset to memory stream, then use the System.IO.Compression library to compress. The DeflateStream class uses the same compression algorithm as the gzip data format used by the GZipStream class.

The compression functions in DeflateStream and GZipStream are exposed as a stream. Data is read on a byte-by-byte basis, so it's not possible to perform multiple passes to determine the best method for compressing entire files or large blocks of data.

The DeflateStream and GZipStream classes are best used on uncompressed sources of data. If the source data is already compressed, using these classes may actually increase the size of the stream.