I have a DataSet consisting of XML data, I can easily output this to a file:
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');
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.
What I’m looking for specifically is:
- a suitable compression library that I can stream the XML to and have the zip file(s) saved to disk
- some sample C# code that can show me how to do this.
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):
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.