<p>I have a DataSet consisting of XML data, I can easily output this to a file:</p>

<pre><code>DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
ds.Load(reader, LoadOption.PreserveChanges, ds.Tables[0]);
ds.WriteXml("C:\\test.xml");
</code></pre>

<p>However what I want to do is compress the XML into a ZIP or other type of compressed file and then just save this file to disk while splitting the ZIP file into 1MB chunks. I do not really want to save the uncompressed file, and then zip it, then split it.</p>

<p><strong>What I'm looking for specifically is:</strong></p>

<ol>
<li>a suitable compression library that I can stream the XML to and have the zip file(s) saved to disk</li>
<li>some sample C# code that can show me how to do this.</li>
</ol>

I've managed to compress a DataSet's XML stream using .NET 2.0's gzip compression.
Here's the blog post I made a few years ago about it:
Saving DataSets Locally With Compression
... and here's the code I added to my DataSet's partial class to write the compressed file (the blog post has the reading code too):
```
```
public void WriteFile(string fileName)
{
    using (FileStream fs = new FileStream(fileName, FileMode.Create))
    {
        Stream s;
        if (Path.GetExtension(fileName) == ".cmx")
        {
            s = new GZipStream(fs, CompressionMode.Compress);
        }
        else if (Path.GetExtension(fileName) == ".cmz")
        {
            s = new DeflateStream(fs, CompressionMode.Compress);
        }
        else
        {
            s = fs;
        }
        WriteXml(s);
        s.Close();
    }
}
```
```
Note that this code uses different compression schemes based on the file's extension. That was purely so I could test one scheme against the other with my DataSet.